Spring Boot应用程序在web.xml中启动应用程序初始化servlet

时间:2019-04-16 01:44:58

标签: java spring spring-boot

@吉文 具有所有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);
    }

}

1 个答案:

答案 0 :(得分:0)

Spring-boot通常比基于xml的配置更喜欢基于注释的配置。默认情况下,Spring df1 = df1.sort_values(['colA','colB']) 通常将驻留在web.xml中,并在spring之前自动被占用。

请参阅此帖子以获取更多详细信息:

DataFrame.sort_values