spring boot内置tomcat设置虚拟目录

//新增如下类,setBaseDirectory即为设置虚拟目录
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE)
@Configuration
@ConditionalOnWebApplication
public class EmbeddedServletContainerAutoConfiguration {
    @Configuration
    @ConditionalOnClass({ Servlet.class, Tomcat.class })
    @ConditionalOnMissingBean(value = EmbeddedServletContainerFactory.class, search = SearchStrategy.CURRENT)
    public static class EmbeddedTomcat {
        @Bean
        public TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory() {
            TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory = new TomcatEmbeddedServletContainerFactory();
            tomcatEmbeddedServletContainerFactory.setBaseDirectory(new File("D://tomcat"));
            return tomcatEmbeddedServletContainerFactory;
        }
    }
}
我们可以查看代码
 
  
 
  
TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer中
 
  
File baseDir = this.baseDirectory != null?this.baseDirectory:this.createTempDir("tomcat");
如果没有baseDirectory则创建一个临时的tmp的目录

你可能感兴趣的:(spring,boot)