如何修改内置tomcat的文档根目录,而不是使用"src/main/webapp“
发布于 2019-06-25 08:48:04
在application.properties
中将文档根目录的路径设置为server.tomcat.document-root
@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);
}
}
}
};
}
发布于 2019-06-24 22:49:43
在application.properties中,添加一个属性:
server.servlet.contextPath=/yourpathgoeshere
https://stackoverflow.com/questions/56712089
复制相似问题