在春季启动应用程序,我有下面的代码用于访问属性文件(errors.properties),当我访问代码,它给出了下面exeception春天开机java.util.MissingResourceException在访问属性文件
exception":"java.util.MissingResourceException","message":"Can't find bundle for base name errors.properties
的errors.properties文件是在src /主/资源/
下面是代码
@Configuration
@PropertySource("classpath:errors.properties") -- tried with both the
entries
@ConfigurationProperties("classpath:errors.properties") --
public class ApplicationProperties {
public static String getProperty(final String key) {
ResourceBundle bundle = ResourceBundle.getBundle("errors.properties");
return bundle.getString(key);
}
}
我无法理解为什么它没有选择资源文件夹下的errors.properties文件,有人可以帮我吗?
给出:500,“错误”:“内部服务器错误”,“异常”:“java.lang.NullPointerException”,“消息”:“无消息可用”,该条目在属性文件中可用但仍给出空指针 – user1245524
@Autowired private static Environment env; env变量变为空而不是自动装配 – user1245524
感谢它的工作,如果我想要使用环境变量加载多个属性文件怎么办?我应该在@PropertySource注释中声明多个文件 – user1245524