简体   繁体   English

Spring Boot WAR 部署

[英]Spring Boot WAR deployment

How can I control in my Spring 2.1.4 Boot application (packaged as a WAR) whether I am creating a servlet 3.1 or 4.0 web application.我如何在我的 Spring 2.1.4 Boot 应用程序(打包为 WAR)中控制我是在创建 servlet 3.1 还是 4.0 Web 应用程序。 Normally, when using a web.xml web application descriptor, the attributes on the web-app would announce the version of the spec being used.通常,当使用 web.xml 网络应用程序描述符时,网络应用程序上的属性会宣布正在使用的规范版本。 In a Spring WebApplicationInitializer application without a web.xml (which is my case), there is no such advertisement.在没有 web.xml 的 Spring WebApplicationInitializer 应用程序中(这是我的情况),没有这样的广告。

Is it just a matter of using only the servlet 3.1 features and deploying them to a container and hope that it works?是否只是使用 servlet 3.1 功能并将它们部署到容器并希望它起作用的问题?

The web.xml file is optional since Servlet 3 and Java EE 6 where annotations such as @WebServlet , @WebFilter , @WebListener were introduced. web.xml文件是可选的,因为 Servlet 3 和 Java EE 6 引入了@WebServlet@WebFilter@WebListener等注释。

However, there is no way to declare this information outside the web.xml using the WebApplicationInitializer so you have to include the file anyway and specify the version.但是,无法使用WebApplicationInitializerweb.xml之外声明此信息,因此无论如何您都必须包含该文件并指定版本。

After more than a year of posting this question I discovered that maven makes such determination by the presence of the specific API declared as a dependency.在发布这个问题一年多之后,我发现 Maven 通过声明为依赖项的特定 API 的存在来做出这样的决定。 For example if you have the javax.servlet:javax.servlet-api:4.0.1 dependency in your Pom file maven will assume a servlet 4.0 container.例如,如果你的 Pom 文件中有 javax.servlet:javax.servlet-api:4.0.1 依赖项,maven 将假定一个 servlet 4.0 容器。 I believe Spring boot does not support this but I think it should.我相信 Spring Boot 不支持这个,但我认为应该支持。 As a sidenote the M2eclipse plug-in also works this way作为旁注,M2eclipse 插件也以这种方式工作

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

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