2016-10-09 4 views
3

Ich bin mit dem folgenden Fehler konfrontiert. Exception in thread "main" java.lang.IllegalArgumentException: Kann nicht Schnittstelle org.springframework.context.ApplicationContextInitializer instanziiert: org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer bei org.springframework.boot.SpringApplication.createSpringFactoriesInstances (SpringApplication.java:414) bei org.springframework.boot.SpringApplication.getSpringFactoriesInstances (SpringApplication.java:394) bei org.springframework.boot.SpringApplication.getSpringFactoriesInstances (SpringApplication.java:385) bei org.springframework.boot.SpringApplication.initialize (SpringApplication .java: 261) unter org.springframework.boot.SpringApplication. (SpringApplication.java:237) unter org.springframework.boot.SpringApplication.run (SpringApplicat ion.java:1191) bei org.springframework.boot.SpringApplication.run (SpringApplication.java:1180)Ausnahme im Thread "Haupt" java.lang.IllegalArgumentException: Kann Schnittstelle nicht instanziieren org.springframework.context.ApplicationContextInitializer

Meine Hauptmethode ist

package proj1; 

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.boot.builder.SpringApplicationBuilder; 
import org.springframework.boot.context.web.SpringBootServletInitializer; 

@SpringBootApplication 
public class WebApplication extends SpringBootServletInitializer { 
    @Override 
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 
     return application.sources(WebApplication.class); 
    } 

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

My pom.xml ist

<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>com.webapp</groupId> 
    <artifactId>proj1</artifactId> 
    <packaging>war</packaging> 
    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.3.5.RELEASE</version> 
    </parent> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>proj1 Maven Webapp</name> 
    <url>http://maven.apache.org</url> 
    <dependencies> 
    <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-core</artifactId> 
      <version>4.0.0.RELEASE</version> 
     </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-autoconfigure</artifactId> 
    <version>1.4.0.RELEASE</version> 
</dependency> 
    <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-tomcat</artifactId> 
      <scope>provided</scope> 
     </dependency> 

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot --> 
<dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>javax.servlet-api</artifactId> 
    <version>3.1.0</version> 
    <scope>provided</scope> 
</dependency> 

     <dependency> 
      <groupId>org.apache.tomcat.embed</groupId> 
      <artifactId>tomcat-embed-jasper</artifactId> 
      <scope>provided</scope> 
     </dependency> 
    </dependencies> 
    <build> 
    <finalName>proj1</finalName> 
    </build> 
</project> 
+0

Ich glaube nicht, dass dies vollständige Stack-Trace-Fehler ist. – luboskrnac

+0

Für den Anfang aufhören zu mischen Framework-Versionen (1.3.5 und 1.4.0). Das Mischen von Versionen eines Frameworks (unabhängig vom Framework) ist sehr schwierig. Außerdem verwenden Sie die Abhängigkeit von Frühjahr 4.0.0, während 4.2 erwartet würde (entfernen Sie die Federkernabhängigkeit, da diese bereits enthalten ist). –

+0

Ich probierte das @ M.Deinum wenn ich die Version auf irgendeinen 1.3.5 oder 1.4.0 ändere gibt es die import org.springframework.boot.SpringApplication kann nicht behoben werden Fehler das ist der Grund, warum ich die versionen anders halte. Bitte Siehe den Beitrag [link] (http://stackoverflow.com/questions/39935456/spring-boot-application-cannot-be-resolved-to-a-type-but-i-imported-it-in-pom-xm) –

Antwort

0

Ihre <dependencies> sollte so etwas wie diese

<?xml version="1.0" encoding="utf-8"?> 
<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>com.webapp</groupId> 
    <artifactId>proj1</artifactId> 
    <packaging>war</packaging> 
    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.3.5.RELEASE</version> 
    </parent> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>proj1 Maven Webapp</name> 
    <url>http://maven.apache.org</url> 
    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-tomcat</artifactId> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.tomcat.embed</groupId> 
      <artifactId>tomcat-embed-jasper</artifactId> 
      <scope>provided</scope> 
     </dependency> 
     <!-- Test Dependencies --> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
    <build> 
     <finalName>proj1</finalName> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

und nicht auf die Mixtur e der Spring Boot (1.3 und 1.4) Versionen und Spring Versionen (4.0, 4.2 und 4.3) wie Sie hatten. Sie haben auch Abhängigkeiten eingeschlossen, die bereits enthalten sind (oder Dinge brechen).

Eine andere Sache ist, dass Sie das spring-boot-maven Plugin haben sollten, das auch in Ihrem Pom fehlt.

+0

Ich habe versucht, diese Pom jetzt gibt es den Fehler Der Import org.springframework.boot.autoconfigure.SpringBootApplication kann nicht aufgelöst werden und SpringBootApplication kann nicht in einen Typ –

+0

behoben werden Fix Ihre Eclipse-Einstellungen (sauber und Reimport) ... Anstatt sich auf Eclipse versucht, von der Befehlszeile aus zu erstellen. Wenn das funktioniert, ist Ihre Sonnenfinsternis geborsten. –

+0

Ich benutze STS Ich habe viele Male gereinigt und wieder importiert, aber das gleiche Problem besteht auch, wenn ich ein neues Projekt erstellen, gibt es das gleiche Problem. –

Verwandte Themen