1.实现AbstractAnnotationConfigDispatcherServletInitializer即可取代web.xml
class="java">
/**
* 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.
*
*
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();
}
}