Same class static factory method
Let’s take an example.
package com.jubilation.spring.user;
public class A {
private A() {
System.out.println(“Object of the class A is created…”);
}
public static A getA()
{
// some object is created and return by this function.
}}
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.A" factory-method=”getA”/>
</beans>
Let’s take an example.
package com.jubilation.spring.user;
public class A {
private A() {
System.out.println(“Object of the class A is created…”);
}
public static A getA()
{
// some object is created and return by this function.
}}
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.A" factory-method=”getA”/>
</beans>
Comments
Post a Comment