简体   繁体   English

Spring Boot制作可部署的WAR文件

[英]Spring boot making deployable WAR file

I am using Spring boot and Spring JPA Data to build a web application. 我正在使用Spring Boot和Spring JPA Data来构建Web应用程序。 The application works fine, but when I try to make WAR file to deploy it inside Tomcat 8 web server, I get these errors 该应用程序运行正常,但是当我尝试制作WAR文件以将其部署到Tomcat 8 Web服务器中时,出现这些错误

Here is my Spring boot start class 这是我的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);
    }
}

and here is my POM file : 这是我的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>

and IntelliJ Idea gives me these Errors : 和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

Spring Boot already contains a Tomcat container inside it, so your generated JAR file is executable. Spring Boot已经在其中包含一个Tomcat容器,因此您生成的JAR文件是可执行的。

Thankfully, Spring authors thought about some ppl still want to deploy Spring Boot apps into an individual container. 幸运的是,Spring作者想到一些ppl仍希望将Spring Boot应用程序部署到一个单独的容器中。 Please follow this link for further info. 请点击此链接以获取更多信息。

You need to configure the Maven/Gradle plugin to generate WAR instead of a JAR. 您需要配置Maven / Gradle插件以生成WAR而不是JAR。

Edit: I just saw that you already have the configuration. 编辑:我刚刚看到您已经有了配置。 If your application is working fine outside of IntelliJ then the issue might be that IntelliJ recognizes your application as a Spring Boot app and tries to run the JAR instead of deploying the WAR file as I think IntelliJ is not prepared for this case. 如果您的应用程序在IntelliJ之外运行良好,则可能是IntelliJ将您的应用程序识别为Spring Boot应用程序,并尝试运行JAR而不是部署WAR文件,因为我认为IntelliJ没有为这种情况做准备。 You might have to write a custom configuration for it. 您可能必须为其编写自定义配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM