java - 部署spring boot应用需要web.xml吗

标签 java web-services spring-boot war

我试图将一个 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/

相关文章:

java - Spring Boot + Elasticsearch : Connection Refused with Java RestHighLevelClient

java - AuthorizationServerConfigurerAdapter 与 WebSecurityConfigurerAdapter 之间的区别

asp.net - 关于webservice异常处理的建议

web-services - 如何从 Spring Boot Endpoint Service 返回自定义 SOAP 错误?

WCF HTTP 504 错误

java - Java 中的位操作 - 根据位值有条件地切换位?

java - spring-boot > 隐式自动注册第 3 方 bean

java - 如何让变量填充android中的ram

java - 将图像保存到 Postgresql Java

java - 如何在 Java 中使用 sudo 权限执行 bash 命令?