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>
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();
}
}
Spring is not the place to store application logic like this.
If you need that, add a getPath()
method that does something like:
public String getPath() {
if(path == null) {
path = getDir() + getPath();
}
return path;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With