2016-05-16 8 views
0

私は、プロジェクトをSpring MVCでコーディングしました。私は春のブートに切り替える。 私はリソースバンドルのプロパティのいずれかを設定するには、以下のコードを使用してファイル:スプリングブート:@Value()アノテーションを使用してリソースバンドルの.propertiesファイルを読み取ることができません

@Bean(name = "appConfig") 
public ReloadableResourceBundleMessageSource appConfig() { 
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource(); 
    messageSource.setBasename("classpath:/appConfig"); 
    messageSource.setCacheSeconds(10); 
    return messageSource; 
} 

私は、コードを実行し、私は下のエラーを取得:男に

Indexing into type 'org.springframework.context.support.ReloadableResourceBundleMessageSource' is not supported 

このコードをお勧めします:

@Bean(name = "appconfig") 
public PropertiesFactoryBean appconfig() { 
    PropertiesFactoryBean bean = new PropertiesFactoryBean(); 
    bean.setLocation(new ClassPathResource("appConfig.properties")); 
    return bean; 
} 

と私はこのエラーを受け取ります:

Property or field 'appConfig' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public? 

何が間違っていますか?

答えて

0

私は、このコードは私のために働いた bean.setLocation(new ClassPathResource("appConfig.properties"));

/
をforgotttenがあります。

@Bean(name = "appConfig") 
public PropertiesFactoryBean appconfig() { 
    PropertiesFactoryBean bean = new PropertiesFactoryBean(); 
    bean.setLocation(new ClassPathResource("/appConfig.properties")); 
    return bean; 
} 

:)

関連する問題