解决Spring Boot打包war部署到Tomcat出现Could not open ServletContext resource

Could not open ServletContext resource [/config/xxx.properties]

SPringBoot打包war部署部署到tomcat出现以上错误。

但是用SpringBoot内置的tomcat调试却正常。

原因:

找不到xxx.properties这个配置文件。

解决:

修改配置文件类的@PropertySource注解

@PropertySource(value = “/config/blogConfig.properties”,encoding = “utf-8”)

@PropertySource(value = “classpath:config/blogConfig.properties”,encoding = “utf-8”)

加上classpath。

因为部署到Tomcat后默认的访问路劲是classpath,直接convenience根路径访问不到。

原文地址:https://www.cnblogs.com/cnsec/p/13286672.html