使用@ContextConfiguration抛出NoClassDefFoundError进行JUnit测试

时间:2018-06-14 15:29:10

标签: java spring junit junit4 spring-3

目前,为了简单起见,我试图运行一个junit测试,只检查泛型类是否是子类的实例。我在测试中创建了一个静态Java Config类。当我运行测试时,我收到java.lang.ClassNotFoundException: org.springframework.core.annotation.AnnotatedElementUtils错误。 Validator类和FiservInstallValidator子类均使用@Component进行注释,位于src/main/java/com.intuit.adminplatformportlets.toolsAdmin下,测试位于src/test/java/com.intuit.adminplatformportlets.toolsAdmin下。我无法理解为什么我的课程无法找到。以下是我的测试和孩子pom

ValidatorTest

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class ValidatorTest {

    @Configuration
    @ComponentScan(basePackages = {
            "com.intuit.adminplatformportlets.toolsAdmin.billpay.validation",
            "com.intuit.adminplatformportlets.toolsAdmin.common.validation"
    })
    static class Config {
    }

    @Qualifier("fiservInstallValidator")
    @Autowired
    Validator<FiservInstallDto> validator;

    @Test
    public void genericsTest() throws Exception {
        assertTrue(validator instanceof FiservInstallValidator);
    }
}

错误

java.lang.NoClassDefFoundError: org/springframework/core/annotation/AnnotatedElementUtils

    at org.springframework.transaction.annotation.SpringTransactionAnnotationParser.parseTransactionAnnotation(SpringTransactionAnnotationParser.java:42)
    at org.springframework.transaction.annotation.AnnotationTransactionAttributeSource.determineTransactionAttribute(AnnotationTransactionAttributeSource.java:154)
    at org.springframework.transaction.annotation.AnnotationTransactionAttributeSource.findTransactionAttribute(AnnotationTransactionAttributeSource.java:133)
    at org.springframework.transaction.interceptor.AbstractFallbackTransactionAttributeSource.computeTransactionAttribute(AbstractFallbackTransactionAttributeSource.java:149)
    at org.springframework.transaction.interceptor.AbstractFallbackTransactionAttributeSource.getTransactionAttribute(AbstractFallbackTransactionAttributeSource.java:100)
    at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethod(TransactionalTestExecutionListener.java:150)
    at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:348)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: org.springframework.core.annotation.AnnotatedElementUtils
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 26 more

的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>tools-parent</artifactId>
        <groupId>com.intuit.ifs.AdminPlatformPortlets.toolsAdmin</groupId>
        <version>2.0.42-SNAPSHOT</version>
    </parent>

    <artifactId>tools-portlet</artifactId>
    <packaging>war</packaging>
    <name>Tools Portlets</name>


    <dependencies>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>coherence</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-asm</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc-portlet</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.portlet</groupId>
            <artifactId>portlet-api</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
        </dependency>
        <dependency>
        <groupId>velocity</groupId>
            <artifactId>velocity</artifactId>
        </dependency>
        <dependency>
            <groupId>velocity</groupId>
            <artifactId>velocity-dep</artifactId>
        </dependency>
        <dependency>
            <groupId>velocity-tools</groupId>
            <artifactId>velocity-tools</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-digester</groupId>
            <artifactId>commons-digester</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-configuration</groupId>
            <artifactId>commons-configuration</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-validator</groupId>
            <artifactId>commons-validator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
        </dependency>
        <dependency>
            <groupId>com.intuit.ifs.afeLibrary</groupId>
            <artifactId>soabase-impl</artifactId>
        </dependency>
        <dependency>
            <groupId>com.intuit.ifs.AdminPlatform.core</groupId>
            <artifactId>admin-portal-view</artifactId>
        </dependency>
        <dependency>
            <groupId>com.intuit.ifs.AdminPlatform.core</groupId>
            <artifactId>admin-portal-logging</artifactId>
        </dependency>
        <dependency>
            <groupId>com.intuit.ifs.AdminPlatform.core</groupId>
            <artifactId>admin-portal-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.intuit.ifs.afeLibrary</groupId>
            <artifactId>util-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.intuit.ifs.afeLibrary</groupId>
            <artifactId>portlet-impl</artifactId>
        </dependency>
        <dependency>
            <groupId>com.intuit.ifs.AdminPlatformPortlets.commonComponents.rest-clients</groupId>
            <artifactId>certman-rest-client</artifactId>
        </dependency>
        <dependency>
            <groupId>com.intuit.ifs.AdminPlatformPortlets.commonComponents.rest-clients</groupId>
            <artifactId>billPay-rest-client</artifactId>
        </dependency>
        <dependency>
            <groupId>com.intuit.ifs.AdminPlatformPortlets.commonComponents.rest-clients</groupId>
            <artifactId>cas-rest-client</artifactId>
        </dependency>
        <dependency>
            <groupId>com.intuit.ifs.AdminPlatformPortlets.commonComponents.rest-clients</groupId>
            <artifactId>quickbase</artifactId>
        </dependency>
        <dependency>
            <groupId>com.intuit.ifs.AdminPlatformPortlets.commonComponents.rest-clients</groupId>
            <artifactId>common</artifactId>
        </dependency>
        <dependency>
            <groupId>com.intuit.ifs.AdminPlatformPortlets.commonComponents.rest-clients</groupId>
            <artifactId>apis</artifactId>
        </dependency>
        <dependency>
            <groupId>com.intuit.ifs.AdminPlatformPortlets.commonComponents.rest-clients</groupId>
            <artifactId>easervice-client</artifactId>
        </dependency>
        <dependency>
            <groupId>com.diginsite.tools.services</groupId>
            <artifactId>tis-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.intuit.spi.payments.cdm</groupId>
            <artifactId>payments-cdm-v1</artifactId>
        </dependency>
        <dependency>
            <groupId>com.diginsite.bb.payments.cdm</groupId>
            <artifactId>bbpayments-cdm-v1-1.6</artifactId>
        </dependency>
        <dependency>
            <groupId>com.diginsite.bpp.uiservice</groupId>
            <artifactId>positivepay-cdm</artifactId>
            <version>2.0.0</version>
        </dependency>
        <!-- For marshalling CDM entities using resteasy with JAXB on the server side -->
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxb-provider</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jackson-provider</artifactId>
        </dependency>

        <dependency>
            <groupId>com.intuit.ifs.durableapis</groupId>
            <artifactId>durableapis</artifactId>
        </dependency>
        <dependency>
            <groupId>com.intuit.ifs.durableapis</groupId>
            <artifactId>durableapis</artifactId>
            <classifier>sources</classifier>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
        </dependency>
        <dependency>
            <groupId>com.googlecode.libphonenumber</groupId>
            <artifactId>libphonenumber</artifactId>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-ext</artifactId>
        </dependency>
        <dependency>
            <groupId>com.liferay.portal</groupId>
            <artifactId>portal-service</artifactId>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <dependency>
            <groupId>org.kubek2k</groupId>
            <artifactId>springockito</artifactId>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-csv</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.tika</groupId>
            <artifactId>tika-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.tika</groupId>
            <artifactId>tika-parsers</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>3.2.4.RELEASE</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

修改 我已经尝试将我的spring版本更改为4.3.9.RELEASE,如评论中链接的帖子AnnotatedElementUtils error spring test所示,我仍然遇到同样的错误。

0 个答案:

没有答案