Different class static factory method
Let’s take an example.
package com.jubilation.spring.user;
public class A {
public A() {
System.out.println(“Object of the class A is created…”);
}
}
package com.jubilation.spring.user;
public class B {
public static A getA() {
//some object of class A created here and returned….
}
}
Configuration will be like this
<?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.xsd">
<bean id=”a” class="com.jubilation.spring.user.B" factory-method=”getA”>
</beans>
Let’s take an example.
package com.jubilation.spring.user;
public class A {
public A() {
System.out.println(“Object of the class A is created…”);
}
}
package com.jubilation.spring.user;
public class B {
public static A getA() {
//some object of class A created here and returned….
}
}
Configuration will be like this
<?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.xsd">
<bean id=”a” class="com.jubilation.spring.user.B" factory-method=”getA”>
</beans>
Comments
Post a Comment