4

Config

@Configuration
@PropertySources({
    @PropertySource("classpath*:properties/test-database.properties")
})
public class DataSourceConfiguration {//...
}

Prop location

D:\Projects\opti\dao\src\main\resources\properties\test-database.properties

D:\Projects\opti\dao\src\main\resources marked as resource folder.

Arthur
  • 1,156
  • 3
  • 20
  • 49

2 Answers2

5

To avoid this kind of problem the issue is to set the jboss.server.config.dir in VM arguments like that :

-Djboss.server.config.dir="[jboss_repository]/server/[default-all-standard-standalone]/conf" –server

and u set PropertySource like this :

@Configuration
@PropertySource("file:${jboss.server.config.dir}/file.properties")

Or you set ur property like that

@PropertySource(value = "classpath:application.properties")

When executed, properties will be imported from the application.properties
file, located in the classpath root.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
1

It isn't clear well the your problem considering the details of your question, but a typical problem whit @PropertySource is that yuo have configure a spring bean for manage the properties. In old years in which xml was the best way for configure Spring you used a namespace configuration that configure a spring bean for use proeprties in your bean, mainly with @Value. In java config for benefit of same behaviour you have configure a bean like belove:

@Bean
public static PlaceholderConfigurerSupport propertyPlaceholderConfigurer() {
       return new PropertySourcesPlaceholderConfigurer();
   }

I hope that this can help you

Valerio Vaudi
  • 4,199
  • 2
  • 24
  • 23
  • It is strange, but with Guava Resources.getResource("/properties/test-database.properties") file is not found to. – Arthur May 07 '16 at 10:10
  • I think, it because of gradle, need to think. – Arthur May 07 '16 at 10:22
  • it is clear because with / you have a relative file path you have without / like this: Resources.getResource("properties/test-database.properties") – Valerio Vaudi May 07 '16 at 10:23