在Spring boot中加入web.xml

公司有个项目,有两个子项目,两个独立的工程,我们组用的Spring boot,没有web.xml的,另一个项目组是用的liferay,有liferay6定制的tomcat7,做到中后期,客户说要放在一个tomcat里面,但是spring boot的war包放在liferay的tomcat下报错,特么只好去找怎么在spring boot里面搞个web.xml。。。
先在java/webapp/WEB-INF/下面加入web.xml

<?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配置加入这些(必须的)

<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>

在代码中去掉所有关于Servlet的配置

比如SpringBootServletInitializer

也不能用FilterRegistrationBean和ServletRegistrationBean注册Filter和Servlet了,应该在web.xml里面配置

猜你喜欢

转载自gwj41.iteye.com/blog/2384893