私は2つのmessages.properties
ファイルを持っています。 1つはresources
の中にあり、もう1つはetc
というディレクトリの私の.jarファイルの外にあります。スプリングブート:外部のmessages.propertiesが追加されていますが使用されていません
これは私のPropertiesConfigurationクラスである:私はこれを見るログで
@Configuration
public class PropertiesConfiguration {
@Bean
public PropertyPlaceholderConfigurer properties() {
final PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
ppc.setIgnoreResourceNotFound(true);
final List<Resource> resourceLst = new ArrayList<Resource>();
resourceLst.add(new FileSystemResource("etc/application.properties"));
resourceLst.add(new FileSystemResource("etc/messages.properties"));
resourceLst.add(new FileSystemResource("etc/messages_et.properties"));
ppc.setLocations(resourceLst.toArray(new Resource[]{}));
return ppc;
}
}
:
11:18:43.764 INFO [main] PropertyPlaceholderConfigurer - Loading properties file from file [C:\Users\deniss\IdeaProjects\repgen\etc\application.properties]
11:18:43.764 WARN [main] PropertyPlaceholderConfigurer - Could not load properties from file [C:\Users\deniss\IdeaProjects\repgen\etc\application.properties]: etc\application.properties (The system cannot find the file specified)
11:18:43.764 INFO [main] PropertyPlaceholderConfigurer - Loading properties file from file [C:\Users\deniss\IdeaProjects\repgen\etc\messages.properties]
11:18:43.764 INFO [main] PropertyPlaceholderConfigurer - Loading properties file from file [C:\Users\deniss\IdeaProjects\repgen\etc\messages_et.properties]
私が理解したように私etc
からmessages.properties
がロードされています。アプリケーションが動作しているときは、その値は使用されません。彼らは私のresources
プロジェクトフォルダ内のデフォルトmessages.properties
から来ています。私は何か間違っているのですか?
をあなたがメッセージソースをしたいが、あなたは正しい@sashok_bgプロパティプレースホルダ –
を使用しています。プロジェクトに別の@Configuration Beanを追加しました。 '@Bean \t public ResourceBundleMessageSource messageSource(){'問題は、私の.jar以外のファイルに 'messageSource.setBasename(" ");'を指す方法がわかりません。 '' classpath "'は明らかに動作しません。 –
春の文書によると、クラスパスを追加することは可能です。つまり、.jarの中で意味があります。 –