How to concatenate two String beans in a configuration file in Spring 2.5
java, spring
Solution
Does this work?
<bean id="dir" class="java.lang.String">
<constructor-arg value="c:/work/"
</bean>
<bean id="file" class="java.lang.String">
<constructor-arg value="file.properties" />
</bean>
<bean id="path" factory-bean="dir" factory-method="concat">
<constructor-arg ref="file"/>
</bean>
Notice the usage of `String.concat(java.lang.String)` method as `factory-method`.
But XML isn't really the best place for stuff like this, what about Java `@Configuration`?
@Configuration
public class Cfg {
@Bean
public String dir() {
return "c:/work/";
}
@Bean
public String file() {
return "file.properties";
}
@Bean
public String path() {
return dir() + file();
}
}
Problem
I know that Spring 3.0 and up has EL, but in this case the project is using Spring 2.5 , example: ``` <bean id="dir" class="java.lang.String"> <constructor-arg value="c:/work/" </bean> <bean id="file" class="java.lang.String"> <constructor-arg value="file.properties" /> </bean> <bean id="path" class="java.lang.String"> <constructor-arg value=**dir + file**/> </bean> ```