我在类路径(src/main/ messages_en.properties )中有一个/config,在jar之外,在/config文件夹中有一个。但是,即使在添加了这个标记之后,messages_en.properties( /config )文件夹中的内容也不会覆盖类路径中的内容:
spring.config.location=config/messages_en.properties
我是不是出了问题,或者这在弹簧靴里是不可能的?
请注意,application.properties位于/config文件夹中(外部化配置)。
发布于 2016-08-24 10:11:36
您正在配置spring.config.location,它用于提供外部应用程序配置(外化配置)的位置。
如果要引用外部位置,则应该在路径前面加上file:,例如:
spring.config.location=file:config/application.properties但是,当您使用一个名为messages_en.properties的文件时,它更可能是MessageSource (用于国际化/本地化)使用的属性文件,而不是作为application.properties文件的替代文件。
您也可以通过配置spring.messages.*属性来配置这些消息的外部位置,例如:
spring.messages.basename=file:config/messages您不必添加语言代码(en),因为Spring已经按照惯例来检测正确的消息文件。
根据调用MessageSource时给定的语言,它将打开messages_en.properties或messages_fr.properties或.如果没有为所提供的语言找到属性,则使用messages.properties作为后备。
编辑:看来,只有类路径资源( messages.properties. )和类路径资源()和类路径()才能使用MessageSourceAutoConfiguration,您需要默认的回退(MessageSourceAutoConfiguration)。如果你没有这些,那就没用了。
但是,您仍然可以使用这些属性并使用MessageSource手动创建@ConfigurationProperties。
@Bean
@ConfigurationProperties("spring.messages")
public MessageSource messageSource() {
return new ReloadableResourceBundleMessageSource();
}https://stackoverflow.com/questions/39118979
复制相似问题