【发布时间】:2017-07-05 16:37:10
【问题描述】:
在 Spring Boot 应用程序中,我有以下用于访问属性文件(errors.properties)的代码,当我访问该代码时,它会给出以下异常:
exception":"java.util.MissingResourceException","message":"Can't find bundle for base name errors.properties
errors.properties 文件位于 src/main/resources/ 下
下面是代码
@Configuration
@PropertySource("classpath:errors.properties") // tried with both the annotations
@ConfigurationProperties("classpath:errors.properties") // tried with both the annotations
public class ApplicationProperties {
public static String getProperty(final String key) {
ResourceBundle bundle = ResourceBundle.getBundle("errors.properties");
return bundle.getString(key);
}
}
我无法理解为什么它没有拾取资源文件夹下的 errors.properties 文件,有人可以帮我吗?
【问题讨论】:
标签: java spring spring-boot