Spring boot制作可部署的WAR文件

Spring boot制作可部署的WAR文件,spring,maven,spring-boot,build,war,Spring,Maven,Spring Boot,Build,War,我正在使用SpringBoot和SpringJPA数据构建一个web应用程序。 该应用程序运行良好,但当我尝试创建WAR文件以将其部署到Tomcat8Web服务器中时,会出现以下错误 这是我的春季启动课程 @SpringBootApplication public class SpringBootWebApplication extends SpringBootServletInitializer { @Override protected SpringApplication

我正在使用SpringBoot和SpringJPA数据构建一个web应用程序。 该应用程序运行良好,但当我尝试创建WAR文件以将其部署到Tomcat8Web服务器中时,会出现以下错误

这是我的春季启动课程

@SpringBootApplication
public class SpringBootWebApplication extends SpringBootServletInitializer  {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder 
     application) {
        return application.sources(SpringBootWebApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(SpringBootWebApplication.class, args);
    }
}
这是我的POM文件:

<?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>guru.springframework</groupId>
<artifactId>spring-boot-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>



<name>Spring Boot Web Application</name>
<description>Spring Boot Web Application</description>

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

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <!--<start-class>guru.springframework.SpringBootWebApplication </start-class>-->

</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</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-thymeleaf</artifactId>-->
    <!--</dependency>-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>

    </dependency>

    <!--WebJars-->
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>bootstrap</artifactId>
        <version>3.3.4</version>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>jquery</artifactId>
        <version>2.1.4</version>
    </dependency>


    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>

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


    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>LATEST</version>
    </dependency>

    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
        <version>LATEST</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-ldap</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-openid</artifactId>
    </dependency>


    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>


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

    <!-- hot swapping, disable cache for template, enable live reload -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>



</dependencies>

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

            <version>1.5.1.RELEASE</version>


        </plugin>
    </plugins>
</build>

SpringBoot中已经包含一个Tomcat容器,所以生成的JAR文件是可执行的

谢天谢地,Spring的作者认为一些ppl仍然希望将Spring引导应用程序部署到单个容器中。请关注更多信息

您需要配置Maven/Gradle插件来生成WAR而不是JAR


编辑:我刚刚看到您已经有了配置。如果您的应用程序在IntelliJ之外工作正常,那么问题可能是IntelliJ将您的应用程序识别为Spring Boot应用程序,并尝试运行JAR而不是部署WAR文件,因为我认为IntelliJ没有为这种情况做好准备。您可能需要为其编写自定义配置。

您找到过解决方案吗?我也犯了同样的错误。通过查看stacktrace,我认为问题在于org.eclipse.persistence.jpa.modelgen.processor类出于某种原因需要groovy.lang.closure。我是SpringBoot和Maven的新手,所以我不知道如何解决这个问题。
Error:java: com.sun.tools.javac.code.Symbol$CompletionFailure: class file 
for groovy.lang.Closure not found
Error:java: java.lang.RuntimeException: 
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for 
groovy.lang.Closure not found