Add web.xml to Spring boot

The company has a project with two sub-projects and two independent projects. Our group uses Spring boot, but there is no web.xml. Another project group uses liferay, which has tomcat7 customized by liferay6. It is said to be placed in a tomcat, but the war package of spring boot is placed under the tomcat of liferay and an error is reported, so I have to find out how to make a web.xml in spring boot. . .
First add web.xml under java/webapp/WEB-INF/

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>com.robbie.SpringBootTraditionalApplication</param-value>
	</context-param>
	<listener>
		<listener-class>org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener</listener-class>
	</listener>
	<servlet>
		<servlet-name>appServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextAttribute</param-name>
			<param-value>org.springframework.web.context.WebApplicationContext.ROOT</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>appServlet</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
</web-app>

 maven configuration add these (required)

 

 

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-legacy</artifactId>
    <version>1.1.0.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Remove all servlet configuration from the code

 

比如SpringBootServletInitializer

You can't use FilterRegistrationBean and ServletRegistrationBean to register Filter and Servlet, they should be configured in web.xml

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326349511&siteId=291194637