我试图将一个 spring boot 应用程序打包为一个 war。根据this ,我修改了我的应用程序类:
@SpringBootApplication
@EntityScan({"org.mdacc.rists.cghub.model"})
@EnableJpaRepositories(basePackages = {"org.mdacc.rists.cghub.ws.repository"})
public class Application extends SpringBootServletInitializer
{
public static void main( String[] args )
{
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
还在我的 pom.xml 中添加了以下内容
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
当我打包项目时,我得到了以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project cg-web: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
当我阅读 spring boot 应用程序时,我从未看到任何关于创建 web.xml 的内容。将 spring boot 应用部署为 war 是否需要 web.xml?
最佳答案
根据 this通过将以下代码段添加到您的 pom.xml 中,让 Maven 忽略 web.xml 的缺失:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
关于java - 部署spring boot应用需要web.xml吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36315591/