【发布时间】:2019-09-06 00:57:40
【问题描述】:
@给定 带有所有 servlet 映射和 contextConfigLocations 的 Web.xml 以加载 spring bean。
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>SpringBootAppWithWebxml</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/appServlet/spring-context-config.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/appServlet/servlet-context.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>sampleServlet</servlet-name>
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sampleServlet</servlet-name>
<url-pattern>/sample/*</url-pattern>
</servlet-mapping>
</web-app>
如何使用 SpringBoot 应用程序加载这个 web.xml 和相应的 servlet 和 contextConfig?
Web.xml 位于模块 A 中,调用应用程序 B 具有模块 A 作为依赖项。
我的springBootapp是
@SpringBootApplication(scanBasePackages = {"com.test.package"})
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class StarterApp{
public static void main(String[] args) {
SpringApplication.run(StarterApp.class);
}
}
【问题讨论】:
-
你没有。当应用程序部署为战争时,
web.xml必须位于特定位置才能被拾取。这根本不适用于使用嵌入式容器运行的 Spring Boot 应用程序。
标签: java spring spring-boot