Reputation: 11455
How to import a properties file and access a property while using Java configuration to configure Spring.
I want to do all in java. Is there a way to do it?
I tried to use @ImportResource("classpath:config.properties")
but did not work.
Upvotes: 9
Views: 14875
Reputation: 7218
I've done this on my @Configuration
class using:
@PropertySource(value="classpath:application.properties")
You can get the properties in number a number of ways:
Inject Environment
into configuration beans that need the properties and use environment.getProperty("my.property.value")
, or
Annotate a property with @Value
as outlined here.
Upvotes: 21