Reputation: 21
How do I modify the document root of the built-in tomcat instead of using the "src/main/webapp"
Upvotes: 1
Views: 1822
Reputation: 21
Set the path to your document root as server.tomcat.document-root
in 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);
}
}
}
};
}
Upvotes: 1
Reputation: 998
In your application.properties, add a property:
server.servlet.contextPath=/yourpathgoeshere
Upvotes: -1