<?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">
<bean id="testDTO" class="di.dto.TestDTO" />
<bean id="testDTO2" class="di.dto.TestDTO"/>
</beans>
package di.main;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import di.dto.TestDTO;
public class TestScope {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("di/config/test.xml");
TestDTO dto1 = (TestDTO) ctx.getBean("testDTO");
TestDTO dto2 = (TestDTO) ctx.getBean("testDTO");
TestDTO dto3 = (TestDTO) ctx.getBean("testDTO2");
System.out.println("dto1 : "+dto1);
System.out.println("dto2 : "+dto2);
System.out.println("testDTO2 : "+dto3);
System.out.println("dto1==dto2 : "+(dto1==dto2));
System.out.println("dto1==dto3 : "+(dto1==dto3));
}
}
<?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">
<bean id="testDTO" class="di.dto.TestDTO" scope="prototype"/>
<bean id="testDTO2" class="di.dto.TestDTO"/>
</beans>
package di.main;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import di.dto.TestDTO;
public class TestScope {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("di/config/test.xml");
TestDTO dto1 = (TestDTO) ctx.getBean("testDTO");
TestDTO dto2 = (TestDTO) ctx.getBean("testDTO");
TestDTO dto3 = (TestDTO) ctx.getBean("testDTO2");
System.out.println("dto1 : "+dto1);
System.out.println("dto2 : "+dto2);
System.out.println("testDTO2 : "+dto3);
System.out.println("dto1==dto2 : "+(dto1==dto2));
System.out.println("dto1==dto3 : "+(dto1==dto3));
}
}