我正在从我的存储库项目编写集成测试,需要加载我的infra项目的IT测试上下文,但由于某种原因,它失败了一些奇怪的异常
java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:673)
at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:480)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:306)
at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:241)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:88)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:70)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3217)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3224)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3224)
at java.lang.Class.getAnnotation(Class.java:3176)
at org.junit.internal.builders.IgnoredBuilder.runnerForClass(IgnoredBuilder.java:10)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:31)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestMethodReference.<init>(JUnit4TestMethodReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:54)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
我想添加的相同配置在Infra项目中运行良好。
为什么我不能在其他地方导入该配置?
这是上下文配置:
@ContextConfiguration( classes = {InfraTestsContextConfiguration.class, RepositoryITContext.class, StandaloneDataSourceConfig.class, TransactionManagerConfig.class, LiquibaseConfig.class},
loader = AnnotationConfigContextLoader.class )
我要加载的InfraTestsContextConfiguration
是:
@Configuration
@ComponentScan(basePackages = {"com.X.infra"},
excludeFilters = {@ComponentScan.Filter(pattern = "com.X.infra.spring.InfraContextConfiguration", type = FilterType.REGEX)})
尽量在这里尽可能清楚,因为我自己并没有真正得到这个
由于
答案 0 :(得分:2)
这听起来像是来自另一个项目的特定于测试的@Configuration
类在类路径中不可见。例如,如果您的InfraTestsContextConfiguration
不在主源代码文件夹中,那么它可能不可见。因此,解决方案是使它们可见,实现这一点的方法取决于您的构建软件(例如Maven)或您的IDE(例如Eclipse)。
这听起来类似于以下主题中的评论中讨论的观点:https://stackoverflow.com/a/24703689/388980