2016-03-07 30 views
6

tôi có một dự án mùa xuân và cố gắng làm cho nó sử dụng khởi động mùa xuân và chạy ở tomcat embadded sau:Run lỗi ứng dụng khởi động mùa xuân: Không thể khởi tạo giao diện org.springframework.context.ApplicationListener

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

này là ứng dụng của tôi

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

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

} 

Nếu tôi sử dụng lệnh maven: mvn spring-boot:run, dự án bắt đầu tốt, nhưng tôi cần phải gỡ rối, vì vậy tôi chạy phương pháp chính này tại InteliJ, ngoại lệ xảy ra:

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 
.... 

Đây là 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> 
+0

Bạn đã kiểm tra http://stackoverflow.com/questions/31489947/noclassdeffounderror-genericapplicationlistener-when- switch-from-spring-bo –

Trả lời

8

Đây là một triệu chứng của một phiên bản không phù hợp đâu đó trong phụ thuộc mùa xuân của bạn, nhưng không nhất thiết chỉ là mùa xuân Boot và mùa xuân của chính nó. Tôi có điều này giữa mùa xuân Boot mẹ tôi:

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

và phụ thuộc mùa xuân đám mây Config của tôi:

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

Đối với một số lý do, tôi không thể xác định sự phụ thuộc vào mùa xuân-cloud-config-client mà không một tuyên bố phiên bản rõ ràng.

Cập nhật cả phiên bản phát hành mới nhất (1.3.5.RELEASE và 1.1.1.RELEASE) đã giải quyết.

0

tôi đã có lỗi tương tự, tôi chỉ cần thay đổi các phiên bản phát hành của phụ huynh khởi động mùa xuân và bây giờ mọi thứ hoạt động đúng

+0

Nên bình luận giải thích chi tiết hơn. –

Các vấn đề liên quan