java.lang.LinkageError:loader constraint violation:loader(org / apache / catalina / loader / WebappClassLoader的实例)

时间:2016-09-28 07:13:46

标签: java maven tomcat integration-testing maven-plugin

  

无法启动组件[StandardEngine [Tomcat] .StandardHost [localhost] .StandardContext [/ projectname]]

     

引起:java.lang.LinkageError:加载器约束违规:加载器(org / apache / catalina / loader / WebappClassLoader的实例)先前为名称为#34; javax / servlet / ServletContext&#34的其他类型启动加载;

     

org.apache.catalina.LifecycleException:无法启动组件[StandardEngine [Tomcat] .StandardHost [localhost]]

在打印堆栈跟踪中,它也没有给出任何ClassNotFoundException :HttpServletRequest

我在pom.xml文件中添加了tomcat maven插件。我想运行一些集成测试,所以我在集成开始之前添加了插件来运行。这是我的插件

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <port>8989</port>
        <systemProperties>
            <archaius.deployment.environment>test</archaius.deployment.environment>
        </systemProperties>
        <path>/${project.name}</path>
    </configuration>
    <executions>
        <execution>
            <id>tomcat-run</id>
            <goals>
                <goal>run</goal>
            </goals>
            <phase>pre-integration-test</phase>
            <configuration>
                <systemProperties>
                    <!-- We want test configuration for running integration tests. -->
                    <archaius.deployment.environment>test</archaius.deployment.environment>
                    <logback-lib.env>filesystem</logback-lib.env>
                </systemProperties>
                <fork>true</fork>
            </configuration>
        </execution>
        <execution>
            <id>tomcat-shutdown</id>
            <goals>
                <goal>shutdown</goal>
            </goals>
            <phase>post-integration-test</phase>
        </execution>
    </executions>
</plugin>

我在pom.xml文件中添加了这个插件。

我还添加了servlet dependency,并仅将范围设为provided

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>

当我mvn clean install给出以下异常时

  

严重:子容器在启动时失败       java.util.concurrent.ExecutionException:org.apache.catalina.LifecycleException:无法启动组件[StandardEngine [Tomcat] .StandardHost [localhost] .StandardContext [/ projectpath]]       at java.util.concurrent.FutureTask.report(FutureTask.java:122)       在java.util.concurrent.FutureTask.get(FutureTask.java:192)       在org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)       在org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800)       在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)       在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1559)       在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1549)       at java.util.concurrent.FutureTask.run(FutureTask.java:266)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)       在java.lang.Thread.run(Thread.java:745)         引起:org.apache.catalina.LifecycleException:无法启动组件[StandardEngine [Tomcat] .StandardHost [localhost] .StandardContext [/ projectpath]]       在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)       ......还有6个         引起:java.lang.LinkageError:加载器约束违规:加载器(org / apache / catalina / loader / WebappClassLoader的实例)先前为名称为#34; javax / servlet / ServletContext&#34;的其他类型启动加载       at java.lang.ClassLoader.defineClass1(Native Method)       at java.lang.ClassLoader.defineClass(ClassLoader.java:763)       at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)       at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)       在java.net.URLClassLoader.access $ 100(URLClassLoader.java:73)       在java.net.URLClassLoader $ 1.run(URLClassLoader.java:368)       在java.net.URLClassLoader $ 1.run(URLClassLoader.java:362)       at java.security.AccessController.doPrivileged(Native Method)       at java.net.URLClassLoader.findClass(URLClassLoader.java:361)       在org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1191)       在org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1669)       在org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)       at java.lang.Class.getDeclaredMethods0(Native Method)       at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)       at java.lang.Class.getDeclaredMethods(Class.java:1975)       at org.apache.catalina.util.Introspection.getDeclaredMethods(Introspection.java:127)       at org.apache.catalina.startup.WebAnnotationSet.loadMethodsAnnotation(WebAnnotationSet.java:281)       在org.apache.catalina.startup.WebAnnotationSet.loadApplicationFilterAnnotations(WebAnnotationSet.java:113)       在org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:66)       在org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:405)       在org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:881)       在org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:376)       在org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)       在org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)       at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5322)       在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)       ......还有6个

     

2016年9月28日下午12:29:26 org.apache.catalina.core.ContainerBase startInternal        严重:子容器在启动时失败         java.util.concurrent.ExecutionException:org.apache.catalina.LifecycleException:无法启动组件[StandardEngine [Tomcat] .StandardHost [localhost]]       at java.util.concurrent.FutureTask.report(FutureTask.java:122)       在java.util.concurrent.FutureTask.get(FutureTask.java:192)       在org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)       在org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)       在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)       在org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)       在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)       在org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)       在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)       在org.apache.catalina.startup.Tomcat.start(Tomcat.java:341)       在org.apache.tomcat.maven.plugin.tomcat7.run.AbstractRunMojo.startContainer(AbstractRunMojo.java:1238)       在org.apache.tomcat.maven.plugin.tomcat7.run.AbstractRunMojo.execute(AbstractRunMojo.java:592)       在org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)       在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)       在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)       在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)       在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)       在org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)       在org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)       在org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)       在org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)       在org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)       在org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)       在org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)       在org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)       在org.apache.maven.cli.MavenCli.main(MavenCli.java:199)       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       at java.lang.reflect.Method.invoke(Method.java:498)       在org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)       在org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)       在org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)       在org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)         引起:org.apache.catalina.LifecycleException:无法启动组件[StandardEngine [Tomcat] .StandardHost [localhost]]       在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)       在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1559)       在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1549)       at java.util.concurrent.FutureTask.run(FutureTask.java:266)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)       在java.lang.Thread.run(Thread.java:745)        引起:org.apache.catalina.LifecycleException:子容器在启动期间失败       在org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)       在org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800)       在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)       ......还有6个

1 个答案:

答案 0 :(得分:6)

我解决了这个问题, 实际上javax.servlet内部由其他依赖项http-libcommons-util启用。

我用过

<exclusions>
    <exclusion>
         <artifactId>servlet-api</artifactId>
        <groupId>javax.servlet</groupId>
    </exclusion>
</exclusions>

在两个依赖项中。然后问题解决了