Sunday 15 February 2015

spring - How to pass a map with application.properties -



spring - How to pass a map<String,String> with application.properties -

i have implemented authorization in webservice needs configured.

currently user/password combo hardcoded bean configuration. configure map users , passwords application.properties configuration can external.

any clue on how can done?

<bean id="basicauthorizationinterceptor" class="com.test.basicauthauthorizationinterceptor"> <property name="users"> <map> <entry key="test1" value="test1"/> <entry key="test2" value="test2"/> </map> </property> </bean>

a java.util.properties object map, hashtable in turn implements map.

so when create properties file (lets name users.properties) should able load using propertiesfactorybean or <util:properties /> , inject class.

test1=test1 test2=test2

then

<util:properties location="classpath:users.properties" id="users" /> <bean id="basicauthorizationinterceptor" class="com.test.basicauthauthorizationinterceptor"> <property name="users" ref="users" /> </bean>

although if have map<string, string> type of users property might fail... wouldn't set them in application.properties file. might me..

spring spring-boot

No comments:

Post a Comment