0 votes
in Spring by

How to inject a java.util.Properties into a Spring Bean?

1 Answer

0 votes
by
We need to define propertyConfigurer bean that will load the properties from the given property file. Then we can use Spring EL support to inject properties into other bean dependencies. For example;

<bean id="propertyConfigurer"

  class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">

    <property name="location" value="/WEB-INF/application.properties" />

</bean>

<bean class="com.journaldev.spring.EmployeeDaoImpl">

    <property name="maxReadResults" value="${results.read.max}"/>

</bean>

If you are using annotation to configure the spring bean, then you can inject property like below.

@Value("${maxReadResults}")

private int maxReadResults;

Related questions

0 votes
asked Apr 4, 2021 in Spring by Robindeniel
0 votes
asked Jul 26, 2020 in Spring by SakshiSharma
...