下面列出了org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory#setContextPath ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
tomcat.addInitializers(new ServletContextInitializer(){
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
XmlWebApplicationContext context = new XmlWebApplicationContext();
context.setConfigLocations(new String[]{"classpath:applicationContext-springmvc.xml"});
DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
ServletRegistration.Dynamic dispatcher = servletContext
.addServlet("dispatcher", dispatcherServlet);
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
});
tomcat.setContextPath("/manager");
tomcat.addTldSkipPatterns("xercesImpl.jar","xml-apis.jar","serializer.jar");
tomcat.setPort(port);
return tomcat;
}
@Bean
public ServletWebServerFactory servletContainer() throws Exception {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
int apiPort = Utils.getSystemPort(Constants.SYS_API_PORT);
factory.setPort(apiPort);
factory.getSession().setTimeout(Duration.ofMinutes(10));
factory.setContextPath("/testproxy");
baseDirectory = new File("./tmp");
factory.setBaseDirectory(baseDirectory);
List<TomcatConnectorCustomizer> cs = new ArrayList();
cs.add(tomcatConnectorCustomizers());
factory.setTomcatConnectorCustomizers(cs);
if (Utils.getEnvironmentOptionValue(Constants.SYS_LOGGING_DISABLED) != null) {
HistoryService.getInstance().disableHistory();
}
return factory;
}
@Override
public void customize(TomcatServletWebServerFactory factory) {
factory.setPort(9090);
factory.setContextPath("/demo");
}