1.实现AbstractAnnotationConfigDispatcherServletInitializer即可取代web.xml
2.
/**
* Base class for {@link org.springframework.web.WebApplicationInitializer}
* implementations that register a
* {@link org.springframework.web.servlet.DispatcherServlet DispatcherServlet}
* configured with annotated classes, e.g. Spring's
* {@link org.springframework.context.annotation.Configuration @Configuration} classes.
*
* <p>Concrete implementations are required to implement {@link #getRootConfigClasses()}
* and {@link #getServletConfigClasses()} as well as {@link #getServletMappings()}.
* Further template and customization methods are provided by
* {@link AbstractDispatcherServletInitializer}.
*
* @author Arjen Poutsma
* @author Chris Beams
* @since 3.2
*/
public abstract class AbstractAnnotationConfigDispatcherServletInitializer
2.
/**
* 添加Servlet
*/
protected void registerDispatcherServlet(ServletContext servletContext) {
super.registerDispatcherServlet(servletContext);
try {
ServletRegistration.Dynamic dynamic= servletContext.addServlet("frontPay", (HttpServlet)Class.forName("com.unionpay.upop.sdk.common.FrontPayServLet").newInstance());
dynamic.addMapping("/frontPay");
} catch (Exception e)
{
e.printStackTrace();
}
}
本文详细介绍了如何使用抽象注解配置DispatcherServlet初始化器来替代web.xml,实现Spring MVC应用的初始化,包括如何注册自定义的Servlet,并通过示例代码展示了具体实现过程。
1262

被折叠的 条评论
为什么被折叠?



