[英]How do frameworks (like Spring) configure the Servlet container without web.xml?
[英]How to configure spring-boot servlet like in web.xml?
我在 web.xml 中有一个简单的 servlet 配置:
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.atmosphere.cpr.MeteorServlet</servlet-class>
<init-param>
<param-name>org.atmosphere.servlet</param-name>
<param-value>org.springframework.web.servlet.DispatcherServlet</param-value>
</init-param>
<init-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>net.org.selector.animals.config.ComponentConfiguration</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>
如何为 SpringBootServletInitializer 重写它?
如果我从表面上看你的问题(你想要一个复制你现有应用程序的SpringBootServletInitializer
),我想它看起来像这样:
@Configuration
public class Restbucks extends SpringBootServletInitializer {
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Restbucks.class, ComponentConfiguration.class);
}
@Bean
public MeteorServlet dispatcherServlet() {
return new MeteorServlet();
}
@Bean
public ServletRegistrationBean dispatcherServletRegistration() {
ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet());
Map<String,String> params = new HashMap<String,String>();
params.put("org.atmosphere.servlet","org.springframework.web.servlet.DispatcherServlet");
params.put("contextClass","org.springframework.web.context.support.AnnotationConfigWebApplicationContext");
params.put("contextConfigLocation","net.org.selector.animals.config.ComponentConfiguration");
registration.setInitParameters(params);
return registration;
}
}
有关更多详细信息,请参阅有关转换现有应用程序的文档。
但是,与使用 Atmosphere 相比,现在使用 Tomcat 和 Spring 中的原生 Websocket 支持可能会更好(请参阅websocket 示例和指南以获取示例)。
我有与Same Dispatch Servlet中类似的要求-多个RequestHandler,但无法使其正常工作。 有指针吗? @戴夫·瑟
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.