작동하지 않습니다 ("프로토 타입")는 다음과 같은 구성을@Scope 제대로
public class MainApp {
public static void main(String args[]){
ApplicationContext ac=new ClassPathXmlApplicationContext("src/Beans.xml");
HelloWorld obj1=(HelloWorld) ac.getBean("helloWorld");
obj1.setMessage("OBJ1");
HelloWorld obj2=(HelloWorld) ac.getBean("helloWorld");
//obj2.setMessage("OBJ2");
System.out.println(obj1.getMessage());
System.out.println(obj2.getMessage());
}
}
@Scope("prototype")
public class HelloWorld {
String message;
public String getMessage() {
return "Your Message:"+message;
}
public void setMessage(String message) {
this.message = message;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="SpringDemo.src" />
<bean id="helloWorld" class="src.HelloWorld">
</bean>
</beans>
을 고려하십시오. 누군가가 왜 "프로토 타입"범위로 행동하지 않는지 알려주실 수 있습니까?
'src.HelloWorld' 클래스 이름이 잘못되었습니다. 'src' 디렉토리를'package'로 지정할 필요가 없습니다 –
제거하면 에러가납니다 클래스 경로 [src/Beans.xml]에 'helloWorld'라는 이름의 bean이있는 클래스 [HelloWorld]를 찾을 수 없습니다. ; 나는 결과를 얻고 있지만 싱글 톤 스코프가 아닌 프로토 타입은 – Aashish
입니다. @Aashish 여러분이보고있는 동작은 정확히 무엇입니까? – soulcheck