Java Spring conflict dependecy versions with Sprin

2019-07-29 14:24发布

问题:

HTTP Status 500 - Servlet.init() for servlet dispatcher threw exception

type Exception report

message Servlet.init() for servlet dispatcher threw exception

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet.init() for servlet dispatcher threw exception
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.lang.Thread.run(Thread.java:745)
root cause

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Invocation of init method failed; nested exception is java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    org/springframework/web/servlet/mvc/condition/ProducesRequestCondition.compareMatchingMediaTypes(Lorg/springframework/web/servlet/mvc/condition/ProducesRequestCondition;ILorg/springframework/web/servlet/mvc/condition/ProducesRequestCondition;I)I @89: invokevirtual
  Reason:
    Type 'org/springframework/http/MediaType' (current frame, stack[1]) is not assignable to 'org/springframework/util/MimeType'
  Current Frame:
    bci: @89
    flags: { }
    locals: { 'org/springframework/web/servlet/mvc/condition/ProducesRequestCondition', 'org/springframework/web/servlet/mvc/condition/ProducesRequestCondition', integer, 'org/springframework/web/servlet/mvc/condition/ProducesRequestCondition', integer, integer, 'org/springframework/web/servlet/mvc/condition/ProducesRequestCondition$ProduceMediaTypeExpression', 'org/springframework/web/servlet/mvc/condition/ProducesRequestCondition$ProduceMediaTypeExpression' }
    stack: { 'org/springframework/http/MediaType', 'org/springframework/http/MediaType' }
  Bytecode:
    0000000: 0336 051c 1504 9f00 0c15 041c 6436 05a7
    0000010: 004f 1c02 9f00 4a15 0402 9f00 442b b701
    0000020: 031c b901 1a02 00c0 0079 3a06 2db7 0103
    0000030: 1504 b901 1a02 00c0 0079 3a07 1906 1907
    0000040: b601 1236 0515 0599 0008 1505 a700 1019
    0000050: 06b6 0111 1907 b601 11b6 00fa 3605 1505
    0000060: ac                                     
  Stackmap Table:
    append_frame(@18,Integer)
    append_frame(@79,Object[#121],Object[#121])
    same_locals_1_stack_item_frame(@92,Integer)
    chop_frame(@94,2)

    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
    org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
    org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
    org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
    org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
    org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
    javax.servlet.GenericServlet.init(GenericServlet.java:158)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.lang.Thread.run(Thread.java:745)
root cause

java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    org/springframework/web/servlet/mvc/condition/ProducesRequestCondition.compareMatchingMediaTypes(Lorg/springframework/web/servlet/mvc/condition/ProducesRequestCondition;ILorg/springframework/web/servlet/mvc/condition/ProducesRequestCondition;I)I @89: invokevirtual
  Reason:
    Type 'org/springframework/http/MediaType' (current frame, stack[1]) is not assignable to 'org/springframework/util/MimeType'
  Current Frame:
    bci: @89
    flags: { }
    locals: { 'org/springframework/web/servlet/mvc/condition/ProducesRequestCondition', 'org/springframework/web/servlet/mvc/condition/ProducesRequestCondition', integer, 'org/springframework/web/servlet/mvc/condition/ProducesRequestCondition', integer, integer, 'org/springframework/web/servlet/mvc/condition/ProducesRequestCondition$ProduceMediaTypeExpression', 'org/springframework/web/servlet/mvc/condition/ProducesRequestCondition$ProduceMediaTypeExpression' }
    stack: { 'org/springframework/http/MediaType', 'org/springframework/http/MediaType' }
  Bytecode:
    0000000: 0336 051c 1504 9f00 0c15 041c 6436 05a7
    0000010: 004f 1c02 9f00 4a15 0402 9f00 442b b701
    0000020: 031c b901 1a02 00c0 0079 3a06 2db7 0103
    0000030: 1504 b901 1a02 00c0 0079 3a07 1906 1907
    0000040: b601 1236 0515 0599 0008 1505 a700 1019
    0000050: 06b6 0111 1907 b601 11b6 00fa 3605 1505
    0000060: ac                                     
  Stackmap Table:
    append_frame(@18,Integer)
    append_frame(@79,Object[#121],Object[#121])
    same_locals_1_stack_item_frame(@92,Integer)
    chop_frame(@94,2)

    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.createRequestMappingInfo(RequestMappingHandlerMapping.java:249)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.getMappingForMethod(RequestMappingHandlerMapping.java:192)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.getMappingForMethod(RequestMappingHandlerMapping.java:51)
    org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$1.matches(AbstractHandlerMethodMapping.java:142)
    org.springframework.web.method.HandlerMethodSelector$1.doWith(HandlerMethodSelector.java:61)
    org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:480)
    org.springframework.web.method.HandlerMethodSelector.selectMethods(HandlerMethodSelector.java:57)
    org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.detectHandlerMethods(AbstractHandlerMethodMapping.java:139)
    org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:109)
    org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:89)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:163)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
    org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
    org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
    org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
    org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
    org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
    javax.servlet.GenericServlet.init(GenericServlet.java:158)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.lang.Thread.run(Thread.java:745)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.54 logs.

Apache Tomcat/7.0.54

It I can see when I try to run my web application based on Spring. I read few articles where i could understood that this problem may be appear when you use different versions of dependencies. In my application I use Spring 4.0.1 version and Spring-Security only 3.2.5 because isn't the latest version. If my problem compose in this thing please advice me what i can do.

pom.xml

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>fullproject</groupId>
    <artifactId>fullproject</artifactId>
    <packaging>war</packaging>
    <version>1.0</version>
    <name>fullproject</name>
    <repositories>
        <repository>
            <id>eap</id>
            <url>http://maven.repository.redhat.com/techpreview/all</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
     <repository>
      <id>unknown-jars-temp-repo</id>
      <name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name>
      <url>file:${project.basedir}/lib</url>
     </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>eap</id>
            <url>http://maven.repository.redhat.com/techpreview/all</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.2-1003-jdbc4</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.25</version>
        </dependency>     
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>org-apache-commons-logging</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>cglib-2.2</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-aop-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-aspects-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-beans-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-build-src-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-context-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-context-support-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-core-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-expression-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-framework-bom-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-instrument-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-instrument-tomcat-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-jdbc-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-jms-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-messaging-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-orm-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-oxm-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-test-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-tx-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-web-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-webmvc-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-webmvc-portlet-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>spring-websocket-4.0.1.RELEASE</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>javax.servlet.jsp.jstl</groupId>
      <artifactId>javax.servlet.jsp.jstl-api</artifactId>
      <version>1.2.1</version>
     </dependency>
     <dependency>
      <groupId>org.glassfish.web</groupId>
      <artifactId>javax.servlet.jsp.jstl</artifactId>
      <version>1.2.2</version>
     </dependency>
     <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-dbcp2</artifactId>
      <version>2.0.1</version>
     </dependency>
     <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <version>4.1.8.Final</version>
     </dependency>
     <dependency>
      <groupId>unknown.binary</groupId>
      <artifactId>hibernate-jpa-2.0-api-1.0.1.Final</artifactId>
      <version>SNAPSHOT</version>
     </dependency>
     <dependency>
      <groupId>aopalliance</groupId>
      <artifactId>aopalliance</artifactId>
      <version>1.0</version>
     </dependency>
     <dependency>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-web</artifactId>
      <version>3.2.5.RELEASE</version>
     </dependency>
     <dependency>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-config</artifactId>
      <version>3.2.5.RELEASE</version>
     </dependency>
     <dependency>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-core</artifactId>
      <version>3.2.5.RELEASE</version>
     </dependency>
     <dependency>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-taglibs</artifactId>
      <version>3.2.5.RELEASE</version>
     </dependency>
    </dependencies>
    <profiles>
        <profile>
            <!-- When built in OpenShift the 'openshift' profile will be used when 
                invoking mvn. -->
            <!-- Use this profile for any OpenShift specific customization your app 
                will need. -->
            <!-- By default that is to put the resulting archive into the 'webapps' 
                folder. -->
            <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
            <id>openshift</id>
            <build>
                <finalName>fullproject</finalName>
                <plugins>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>2.1.1</version>
                        <configuration>
                            <outputDirectory>webapps</outputDirectory>
                            <warName>ROOT</warName>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

回答1:

Spring 4 has new Bill Of Materials (BOM) feature that should simplify dependency management. You could give that a try as a way to resolve versioning conflicts.

https://spring.io/blog/2013/12/03/spring-framework-4-0-rc2-available

http://blog.inflinx.com/2013/12/29/maven-bill-of-materials/



回答2:

I got the same error when updating the spring dependencies from 3.2.9 to 4.0.9, while using swagger-webmvc 1.0.1. I needed to manually exclude spring-webmvc and spring-web dependencies from swagger and force the usage of spring libraries with version 4.0.9. Definetely this looks like a dependency conflict ...



回答3:

In my case i'm using springboot application in 1.5.1.RELEASE version. Adding Swagger2 dependencies my build was broken because the swagger dependencies was using the spring-beans less version.

When i add exclusions with this, my problem was solved.

ex:

<dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.9.2</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

Hope that this is useful for someone.