java.lang.ClassNotFoundException:org.springframework.context.ApplicationContextInitializer

时间:2017-10-06 09:32:23

标签: spring spring-boot

我尝试启动弹簧启动时遇到此异常:

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextInitializer
        at org.springframework.boot.SpringApplication.initialize(SpringApplication.java:262)
        at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:238)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1187)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1176)
        at org.myapp.test.subscription.webservice.Application.main(Application.java:15)
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContextInitializer
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 5 more

这是我的maven配置:

<!-- SPRING -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>1.4.7.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>1.4.7.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <version>1.4.7.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.6.3.redhat-1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <version>1.4.7.RELEASE</version>
        </dependency>
...
<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.4.7.RELEASE</version>
            </plugin>
...

任何想法为什么?我应该添加另一个依赖项还是使用错误的版本?这可能是与另一个依赖的冲突吗?

2 个答案:

答案 0 :(得分:0)

@ darren-forsythe indeeed是POM配置:

<dependencyManagement>
     <dependencies>
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>1.5.7.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

现在它正在工作,谢谢你!

答案 1 :(得分:0)

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.2.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

上述版本的工作正常