Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/syg.properties]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:159)
at org.springframework.core.io.support.EncodedResource.getReader(EncodedResource.java:143)
at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:95)
at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:73)
at org.springframework.core.io.support.PropertiesLoaderUtils.loadProperties(PropertiesLoaderUtils.java:59)
at org.springframework.core.io.support.ResourcePropertySource.<init>(ResourcePropertySource.java:67)
at org.springframework.core.io.support.DefaultPropertySourceFactory.createPropertySource(DefaultPropertySourceFactory.java:37)
at org.springframework.context.annotation.ConfigurationClassParser.processPropertySource(ConfigurationClassParser.java:462)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:279)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:249)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:198)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:303)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:249)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:206)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:174)
... 26 more
此类问题我们将其归类为配置文件找不到,不管是maven项目,gradle项目,亦或是普通web项目,不管是.properties或者.xml,都是路径问题。
既然是路径问题,通常有三种
1,常用tomcat等容器的默认路径:[不同容器有不同,根据具体使用的容器查找即可]
2,类路径:[class文件所在的位置]
3,自定义路径:[多数会编译到类路径中]
此问题:Could not open resource ,其实重点就是ServletContext,说明是在容器默认路径没找到,因为我们的项目是自定义路径,所以修改一下配置的路径就ok了。
中间涉及到的框架和具体细节没有展开讲,如果需要沟通请添加微信公众号留言:不清不楚的迷茫