File: context.xml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
File: Main.java
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
public class Main {
private static void compare(final BeanFactory factory, final String beanName) {
String b1 = (String)factory.getBean(beanName);
String b2 = (String)factory.getBean(beanName);
System.out.println("Bean b1=" + b1 + ", b2=" + b2);
System.out.println("Same? " + (b1 == b2));
System.out.println("Equal? " + (b1.equals(b2)));
}
public static void main(String[] args) {
BeanFactory factory = new XmlBeanFactory(
new ClassPathResource("context.xml"));
compare(factory, "singleMe");
compare(factory, "prototypeMe");
compare(factory, "requestMe");
}
}
Spring-SingletonScopeAndPrototypeScope.zip( 2,599 k)