java - Spring Multiple Property Placeholder and SPEL order independent -
i have 2 xml config files using property-placeholder. i'm having issue order of import statements these 2 config files effect spel in 1 of config files.
config-a.xml
<context:property-placeholder location="classpath:dev/food.properties" ignore-unresolvable="true" /> <bean id="foodnames" class="java.util.hashmap"> <constructor-arg> <map key-type="com.my.project.food" value-type="java.lang.string"> <entry key="#{t(com.my.project.food).sushi}" value="${dynamodb.sushi:#{null}}" /> </map> </constructor-arg> </bean> config-b.xml
<context:property-placeholder location="classpath:dev/animals.properties" ignore-unresolvable="true" /> if import config-a.xml before config-b.xml, value set in foodnames map. if set config-b.xml before config-a.xml, value null. more visual example can seen below.
spring-dispatcher-servlet.xml
// value set <import resource="classpath:spring/config-a.xml" /> <import resource="classpath:spring/config-b.xml" /> // value null <import resource="classpath:spring/config-b.xml" /> <import resource="classpath:spring/config-a.xml" /> what can make order independent?
the easiest (and suspect recommended approach) use java based configuration. in configuration define bean propertysourcesplaceholderconfigurer , use @propertysource annotations load property files.
@configuration @propertysource("classpath:dev/food.properties") public class configa {} @configuration @propertysource("classpath:dev/animals.properties") public class configb {} @configuration @componentscan("your-packages-here") public class rootconfig { @bean public static propertysourcesplaceholderconfigurer propertysourcesplaceholderconfigurer() { return new propertysourcesplaceholderconfigurer(); } } something this. configuration classes loaded property files before replacement going happen.
Comments
Post a Comment