Eclipse 中的 Spring Boot maven 项目无法在 Intellij 中运行

twi*_*ezo 1 java eclipse intellij-idea maven spring-boot

我有在 eclipse 中创建的工作 spring boot maven 项目。然后我将其导入 Intellij Ultimate,一切正常,单击运行并:

之后我有错误:

2017-02-15 12:46:58.459 ERROR 6020 --- [  restartedMain] o.s.boot.SpringApplication               : Application startup failed

java.lang.IllegalStateException: Could not evaluate condition on org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration due to javax/servlet/Filter not found. Make sure your own configuration does not rely on that class. This can also happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake)

....

2017-02-15 12:46:58.478 ERROR 6020 --- [  restartedMain] o.s.b.f.s.DefaultListableBeanFactory     : Destroy method on bean with name 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory' threw an exception

java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.context.annotation.AnnotationConfigApplicationContext@2f6c79e1: startup date [Wed Feb 15 12:46:56 CET 2017]; root of context hierarchy
Run Code Online (Sandbox Code Playgroud)

哪里有问题 ?

我的 POM.xml

<?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/xsd/maven-4.0.0.xsd">`


<modelVersion>4.0.0</modelVersion>

<groupId>com.twistezo</groupId>
<artifactId>StickyNotes</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>StickyNotes</name>
<description>StickyNotes SpringBoot app</description>

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

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<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.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
    <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-springsecurity4</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
     <dependency>
       <groupId>net.sourceforge.nekohtml</groupId>
        <artifactId>nekohtml</artifactId>
     </dependency>
     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
     </dependency>
     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
         <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

初级班

@SpringBootApplication
public class StickyNotesApplication {

public static void main(String[] args) {
    SpringApplication.run(StickyNotesApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)

Cra*_*der 5

IntelliJ IDEA Maven 支持和依赖项存在一个已知问题provided

解决您的问题的方法是将spring-boot-starter-tomcat依赖范围从更改providedcompile.

另请参阅类似案例的相关讨论,但具有不同的依赖性。