【问题标题】:Spring boot making deployable WAR fileSpring Boot 制作可部署的 WAR 文件
【发布时间】:2017-09-04 10:14:41
【问题描述】:

我正在使用 Spring Boot 和 Spring JPA Data 来构建 Web 应用程序。 该应用程序工作正常,但是当我尝试制作 WAR 文件以将其部署到 Tomcat 8 Web 服务器中时,我收到这些错误

这是我的 Spring boot 启动类

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

IntelliJ Idea 给了我这些错误:

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

【问题讨论】:

  • 您找到解决方案了吗?我遇到了同样的错误。通过查看堆栈跟踪,我认为问题在于 org.eclipse.persistence.jpa.modelgen.processor 类出于某种原因需要 groovy.lang.closure 。我是 Spring Boot 和 Maven 的新手,所以我不知道如何解决这个问题。

标签: spring maven spring-boot build war


【解决方案1】:

Spring Boot 内部已经包含一个 Tomcat 容器,因此您生成的 JAR 文件是可执行的。

谢天谢地,Spring 作者考虑过一些人仍然希望将 Spring Boot 应用程序部署到单独的容器中。请关注this link 了解更多信息。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-03
    • 1970-01-01
    • 1970-01-01
    • 2015-03-10
    • 2018-12-05
    • 2017-05-04
    相关资源
    最近更新 更多