Reputation: 180
I have two packages A and B with a class X within package B. I need to use an instance of a X in A.
Catch here is package B contains Java Bean spring configuration while A uses XML.
Here is how package B's AppConfig looks like.
@Configuration
public class PackageBJavaBeans {
@Bean
public X getX(final String paramOne, final String paramTwo) {
String value = doSomeProcessingWithParameters(paramOne, paramTwo);
return new X(value);
}
private String getXValue(final String paramOne, final String paramTwo){
final String value = //do-some-calculation
return value;
}
}
I need to create a bean of class X in package "A" with XML. How do I pass parameters via XML from package A?
Thanks.
Upvotes: 1
Views: 3001
Reputation: 41
I think this is what you're asking for.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- Definition for X bean -->
<bean id="X" class="A.X">
<constructor-arg value="The value this bean holds"/>
</bean>
</beans>
I'm a little confused on what exactly you want. Do you still want us to use the provided function that would concatenate the two strings together before creating X? That is possible using a factory method. Let me know if you want an example of a factory method bean.
Upvotes: 2