2016-12-01 5 views
0

私は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から来ています。私は何か間違っているのですか?

+1

をあなたがメッセージソースをしたいが、あなたは正しい@sashok_bgプロパティプレースホルダ –

+0

を使用しています。プロジェクトに別の@Configuration Beanを追加しました。 '@Bean \t public ResourceBundleMessageSource messageSource(){'問題は、私の.jar以外のファイルに 'messageSource.setBasename(" ");'を指す方法がわかりません。 '' classpath "'は明らかに動作しません。 –

+0

春の文書によると、クラスパスを追加することは可能です。つまり、.jarの中で意味があります。 –

答えて

0

私はここで、この質問に対する答えがあると思う: Spring Boot and multiple external configuration files

以前の私のために働いたので、それを試してみるする価値があります!

+0

私はこれらのソリューションを試しましたが、私はまだ同じ結果を得ています。メッセージプロパティファイルには別のアプローチが必要なことがあると思います。 –

0

まず、Spring Bootの設定についてはっきりしています。 pom.xmlで

、PropertiesLauncherのレイアウトは、 "ZIP" であると@EnableAutoConfigurationを使用してください回避をする、ので "ZIP"

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
      <configuration> <!-- added --> 
       <layout>ZIP</layout> <!-- to use PropertiesLaunchar --> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

としてレイアウト一度確認してください。

または外部プロパティの@PropertySourceアノテーションを使用してください。 (参照:Spring Boot PropertySource)。

このトピックはすでにStackOverflowによって議論されています。

は参照してください:

Spring Boot: Is it possible to use external application.properties files in arbitrary directories with a fat jar?

Spring @Configuration file with PropertyPlaceholderConfigurer bean doesn't resolve @Value annotation

+0

私の投稿にapplication.propertiesについては何もありません。私はmessages.propertiesについて尋ねています。これは違う。 Application.propertiesは、私の現在の設定でうまく動作します。 –

関連する問題