简体   繁体   English

运行 spring boot 应用程序错误:无法实例化接口 org.springframework.context.ApplicationListener

[英]Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener

I have a spring project and try to make it use spring boot and to run at embadded tomcat following :我有一个 spring 项目,并尝试使用 spring boot 并在以下嵌入式 tomcat 上运行:

https://spring.io/guides/gs/rest-service/ https://spring.io/guides/gs/rest-service/

This is my Application这是我的应用程序

//@Configuration
//@EnableAspectJAutoProxy
@SpringBootApplication
@ComponentScan(basePackages = "gux.prome")
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

If I use maven command: mvn spring-boot:run , the project starts fine, but I need to debug , so I run this main method at InteliJ, exception occurs:如果我使用 maven 命令: mvn spring-boot:run ,项目启动正常,但我需要调试,所以我在 InteliJ 运行这个 main 方法,发生异常:

Exception in thread "main" java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationListener : org.springframework.boot.logging.ClasspathLoggingApplicationListener
    at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:414)
    at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:394)
    at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:385)
    at org.springframework.boot.SpringApplication.initialize(SpringApplication.java:263)
    at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:237)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)
    at gux.prome.config.Application.main(Application.java:19)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.NoClassDefFoundError: org/springframework/context/event/GenericApplicationListener
....

This is the pom:这是pom:

<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>gux</groupId>
  <artifactId>prome-data</artifactId>


  <version>1.0-SNAPSHOT</version>
  <name>prome-data Maven Webapp</name>
  <url>http://maven.apache.org</url>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.3.RELEASE</version>
  </parent>

  <dependencies>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <!-- guava -->
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>18.0</version>
    </dependency>
    <!-- end of guava -->


    <dependency>
      <groupId>joda-time</groupId>
      <artifactId>joda-time</artifactId>
      <version>2.9.2</version>
    </dependency>

  </dependencies>


  <properties>
    <java.version>1.7</java.version>
  </properties>


  <build>

    <finalName>prome-data</finalName>

    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>

      <!--<plugin>-->
      <!-- use java 7 -->
        <!--<artifactId> maven-compiler-plugin</artifactId>-->
        <!--<version>3.1</version>-->
        <!--<configuration>-->
          <!--<source> 1.7</source>   -->
          <!--<target> 1.7</target>-->
        <!--</configuration>-->
      <!--</plugin>-->

    </plugins>
  </build>

  <!--<repositories>-->
    <!--<repository>-->
      <!--<id>spring-releases</id>-->
      <!--<url>http://repo.spring.io/libs-release</url>-->
    <!--</repository>-->
  <!--</repositories>-->

  <!--<pluginRepositories>-->
    <!--<pluginRepository>-->
      <!--<id>spring-releases</id>-->
      <!--<url>http://repo.spring.io/libs-release</url>-->
    <!--</pluginRepository>-->
  <!--</pluginRepositories>-->


</project>

This is a symptom of a version mismatch somewhere in your Spring dependencies, but not necessarily just Spring Boot and Spring itself.这是 Spring 依赖项中某处版本不匹配的症状,但不一定只是 Spring Boot 和 Spring 本身。 I had this between my Spring Boot parent:我在我的 Spring Boot 父母之间有过这个:

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.3.5.RELEASE</version>
  <relativePath></relativePath>
</parent>

and my Spring Cloud Config dependency:和我的 Spring Cloud Config 依赖项:

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-config-client</artifactId>
  <version>1.0.4.RELEASE</version>
</dependency>

For some reason, I am not able to define the spring-cloud-config-client dependency without an explicit version declaration.出于某种原因,如果没有明确的版本声明,我无法定义 spring-cloud-config-client 依赖项。

Updating both to the latest release version (1.3.5.RELEASE and 1.1.1.RELEASE) solved it.更新到最新版本(1.3.5.RELEASE 和 1.1.1.RELEASE)解决了这个问题。

Conclusion结论
Update your dependencies to the latest correct ones将您的依赖项更新为最新的正确依赖项

For ones using Gradle, I solved this issue setting the version of the Spring Boot Gradle Plugin in my library and in my main project to the same value:对于使用 Gradle 的人,我解决了这个问题,将我的库和主项目中的 Spring Boot Gradle 插件的版本设置为相同的值:

plugins {
    id("org.springframework.boot") version "2.2.2.RELEASE"
}

我遇到了同样的错误,我只是更改了 Spring Boot 父级的发布版本,现在一切正常

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行 spring 启动应用程序错误:eclipse intellij 无法实例化接口 org.springframework.context.ApplicationListener - Run spring boot application error: eclipse intellij Cannot instantiate interface org.springframework.context.ApplicationListener java.lang.IllegalArgumentException:无法实例化接口 org.springframework.context.ApplicationListener - java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationListener 线程“main”中的异常 java.lang.IllegalArgumentException:无法实例化接口 org.springframework.context.ApplicationListener - Exception in thread "main" java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationListener 在TomEE中部署org.springframework.context.ApplicationListener异常 - org.springframework.context.ApplicationListener exception deploying in TomEE 无法实例化接口 org.springframework.context.ApplicationContextInitializer (Spring 5.2.3 + Spring Boot 2.2.3) - Cannot instantiate interface org.springframework.context.ApplicationContextInitializer (Spring 5.2.3 + Spring Boot 2.2.3) 构建错误:无法实例化接口org.springframework.boot.SpringApplicationRunListener Spring Boot - build error: Cannot instantiate interface org.springframework.boot.SpringApplicationRunListener Spring Boot java.lang.IllegalArgumentException:无法实例化接口org.springframework.context.ApplicationContextInitializer - java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationContextInitializer 线程“主”java.lang.IllegalArgumentException 中的异常:无法实例化接口 org.springframework.context.ApplicationContextInitializer - Exception in thread "main" java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationContextInitializer 在 aws 上部署 Spring 启动应用程序时,无法创建 org.springframework.orm.jpa.SharedEntityManagerCreator 错误类型的内部 bean - Cannot create inner beanof type org.springframework.orm.jpa.SharedEntityManagerCreator error while Spring boot application deployed on aws Spring Boot:SpringApplication.run导致org.springframework.context.ApplicationContextException: - Spring Boot: SpringApplication.run causes org.springframework.context.ApplicationContextException:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM