Reputation: 1195
I want to load a property file into a spring bean. I found two approaches :
<util.properties>
and inject using @Resource
or @Autowired
I do not want to create @configuraiton bean for this scenario since all spring configurations are maintained in xml.
If i follow the first approach - i dont have the below option to handle the scenario of missing property file @PropertySource(value="classpath:missing.properties", ignoreResourceNotFound=true)
I want the entire property file to be injected since this is lookup file and different keys will be accessed based on the logic. ( hence the context property place holder will not help )
Is there any way i can inject a property file into a bean and also handle the missing file scenario ?
Upvotes: 0
Views: 333
Reputation: 1195
We can achieve it like below
<bean id="myLookUp" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="ignoreResourceNotFound"><value>true</value></property>
<property name="locations">
<list>
<value>classpath:myLookUp.properties</value>
</list>
</property>
</bean>
Upvotes: 0