2016-05-16 10 views
0

nicht lesen Ich hatte Projekt mit Feder MVC codiert. Ich wechsle zum Springboot. I-Code unter Verwendung eines von Ressourcenbündel Eigenschaften festlegen Datei:Spring Boot: kann Ressourcenpaket .properties Dateien mit @Value() Annotation

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

ich den Code ausführen und ich bekomme Fehler unter:

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

Auf guy diesen Code empfohlen:

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

und ich erhalte diesen Fehler:

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

Was mache ich falsch?

Antwort

0

I Have /
in bean.setLocation(new ClassPathResource("appConfig.properties"));

Dieser Code funktioniert für mich forgottten.

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

:)

Verwandte Themen