[英]Getting NPE for @Autowired bean when using custom composed annotation in JUnit Jupiter
@TestMethodOrder(OrderAnnotation.class)
@SpringJUnitWebConfig(locations = { "classpath:service.xml","classpath:data.xml" })
@Tag("1")
public @interface TransactionalIntegrationTest {}
@TransactionalIntegrationTest
public class MyTestTest {
@Autowired
protected CreateUser createUser;
@BeforeEach
public void setUp() throws Exception {
createUser.createTimesheetUser(...)} --> NPE
}
在createUser
上获取NullPointerException。
如果我不使用元注释,那么它将正常工作。
@TestMethodOrder(OrderAnnotation.class)
@SpringJUnitWebConfig(locations = { "classpath:service.xml","classpath:data.xml" })
@Tag("1")
public class MyTestTest {
@Autowired
protected CreateUser createUser;
@BeforeEach
public void setUp() throws Exception {
createUser.createTimesheetUser(...)} --> works now
}
您可能会缺少@Retention
声明,该声明允许诸如Spring和JUnit之类的框架在运行时查看批注。
如下声明您组成的注释应该起作用。
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@TestMethodOrder(OrderAnnotation.class)
@SpringJUnitWebConfig(locations = { "classpath:service.xml", "classpath:data.xml" })
@Tag("1")
public @interface TransactionalIntegrationTest {
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.