2017-04-09 67 views
1

我使用Spring启动和Spring JPA Data来构建一个Web应用程序。 应用程序工作正常,但是当我试图让WAR文件来部署它的Tomcat 8 web服务器里面,我得到这些错误春季启动制作可部署的WAR文件

这里是我的春天开机启动类

@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 

回答

0

Spring Boot已经包含了一个Tomcat容器,所以你生成的JAR文件是可执行的。谢天谢地,Spring作者想到一些ppl仍然想将Spring Boot应用程序部署到单个容器中。请按照this link获取更多信息。

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

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