如何修改内置tomcat的文档根目录,而不是使用“ src / main / webapp”
答案 0 :(得分:0)
在application.properties中,添加一个属性:
server.servlet.contextPath=/yourpathgoeshere
答案 1 :(得分:0)
在server.tomcat.document-root
中添加application.properties
@Value("${server.tomcat.document-root:}")
private String documentRoot;
@Bean
public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer() {
return new WebServerFactoryCustomizer<ConfigurableWebServerFactory>() {
@Override
public void customize(ConfigurableWebServerFactory factory) {
if (factory instanceof TomcatServletWebServerFactory) {
TomcatServletWebServerFactory tomcat = (TomcatServletWebServerFactory) factory;
if (!StringUtils.isEmpty(documentRoot)) {
File root = new File(documentRoot);
tomcat.setDocumentRoot(root);
}
}
}
};
}