不可解决的依赖性org.springframework.core.KotlinDetector.isKotlinReflectPresent()z

时间:2018-10-10 07:04:47

标签: java spring maven spring-mvc

大家好,我在将应用程序部署到tomcat时遇到以下错误。我已经在eclipse中配置了tomcat,并且tomcat的版本是8.5.3,而Java的版本是1.8。

DEBUG   2018-10-10 11:52:09,243 [localhost-startStop-1] org.springframework.web.servlet.DispatcherServlet  - Servlet with name 'spitter' will try to create custom WebApplicationContext context of class 'org.springframework.web.context.support.XmlWebApplicationContext', using parent context [null]
ERROR   2018-10-10 11:52:09,368 [localhost-startStop-1] org.springframework.web.servlet.DispatcherServlet  - Context initialization failed
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.context.support.XmlWebApplicationContext]: Unresolvable class definition; nested exception is java.lang.NoSuchMethodError: org.springframework.core.KotlinDetector.isKotlinReflectPresent()Z
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:132)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:630)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:686)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:554)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:499)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:172)
    at javax.servlet.GenericServlet.init(GenericServlet.java:158)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1144)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1091)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:983)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4978)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5290)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoSuchMethodError: org.springframework.core.KotlinDetector.isKotlinReflectPresent()Z
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:171)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:122)
    ... 22 more

我的pom.xml中具有以下依赖项

<properties>
  <spring-version>5.0.9.RELEASE</spring-version>
  <junit-version>4.12</junit-version>
   <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

  </properties>



   <dependencies>
    <dependency>
       <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${junit-version}</version>
      <scope>test</scope>
    </dependency>

    <dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.3.3</version>
</dependency>
 <dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.17</version>
</dependency>  

<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-web -->
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-web</artifactId>
    <version>5.0.8.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-config -->
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-config</artifactId>
    <version>5.0.8.RELEASE</version>
</dependency>


    <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${spring-version}</version>
</dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring-version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>${spring-version}</version>
    <scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${spring-version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${spring-version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.1</version>

</dependency>

<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>2.0.1.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>6.0.13.Final</version>
</dependency>

<!-- Jackson JSON Processor -->
 <dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.9.4</version>
</dependency> 

  <!-- https://mvnrepository.com/artifact/org.hornetq/hornetq-core -->
<dependency>
    <groupId>org.hornetq</groupId>
    <artifactId>hornetq-core</artifactId>
    <version>2.2.18.Final</version>
</dependency>
  </dependencies>

在我的目标war的lib文件夹中还包含我在pom中声明的所有jar。我试图清理和清理tomcat的工作目录,但仍然遇到相同的错误。

我的web.xml如下

<servlet>
<servlet-name>spitter</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- if we want to use custom configuration file use init param attribute and set contextConfigLocation parameter to our 
custom file otherwise it will look forservletname-servlet.xml file in WEB-INF location -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spitter</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<!-- <filter>
<filter-name>spingSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter> -->
</web-app>

任何人都可以帮助我解决这个问题。谢谢!

2 个答案:

答案 0 :(得分:1)

我遇到了这个问题,我的spring boot项目也有一个依赖关系,另一个jar库包含

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.0.15.RELEASE</version>
</dependency>

尽管我的春季启动项目的版本为5.1.12.RELEASE,但我认为存在jar冲突问题。我将spring-core 5.0.15.RELEASE的版本升级为5.1.12.RELEASE。 然后问题解决了。

请确保所有版本的罐子都匹配。

答案 1 :(得分:0)

对我来说,问题在于spring-core的旧版本(4.x,其余的库位于5.2.8.RELEASE)已经进入,并且是通过spring-retry依赖来的。 mvn依赖项:tree帮助我解决了这个问题。

排除了它,就完成了工作:

<dependency>
  <groupId>org.springframework.retry</groupId>
  <artifactId>spring-retry</artifactId>
  <version>1.3.0</version>
  <exclusions>
    <exclusion>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
    </exclusion>
  </exclusions>
</dependency>