当我在嵌入式tomcat上使用相同的war时,它可以正常工作并从application.properties
文件中读取上下文路径。但是我在独立的tomcat上部署了相同的战争,然后它不从application.properties
文件读取上下文路径,而是使用部署的war文件名作为根上下文。
从jar更改为war后使用以下主类
主类
@SpringBootApplication
@EnableSwagger2
@ComponentScan(basePackages = { "com.it.spc.apihub", "com.it.spc.apihub.api" })
@Configuration
public class Swagger2SpringBoot extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
// Tried all below things too but did not work
Map<String, Object> map = new HashMap<>();
map.put("server.contextPath", "/taas_lite/TaxServlet");
application.application().setDefaultProperties(map);
return application.sources(Swagger2SpringBoot.class);//.properties(getProperties());
}
public static void main(String[] args) throws Exception {
/*SpringApplicationBuilder springApplicationBuilder = new SpringApplicationBuilder(Swagger2SpringBoot.class);
springApplicationBuilder.sources(Swagger2SpringBoot.class)
.properties(getProperties())
.run(args);*/
// Tried all below things too but did not work
SpringApplication springApplication = new SpringApplication(Swagger2SpringBoot.class);
Map<String, Object> map = new HashMap<>();
map.put("server.contextPath", "/taas_lite/TaxServlet");
springApplication.setDefaultProperties(map);
springApplication.run(args);
}
/* static Properties getProperties() {
Properties props = new Properties();
props.put("spring.config.location", "classpath:application.properties");
return props;
}*/
}
application.properties文件内容
server.contextPath=/taas_lite/TaxServlet
server.port=8080