2011-11-14 4 views

답변

21

Use @Scope instead.

또한, DefaultScopes은 스프링 코어에서 사용할 수 없습니다,하지만 당신은 편의를 위해 BeanDefinition.SCOPE_PROTOTYPEBeanDefinition.SCOPE_SINGLETON를 사용할 수 있습니다.

+0

감사합니다. Google에 의외로 힘들었습니다. –

+1

그것의 지금'ConfigurableBeanFactory.SCOPE_PROTOTYPE' – sinu

2

당신은 예를 들어 @Scope("prototype")을 추가 할 수 있습니다

@Bean 
@Scope("prototype") 
public DemoDao getDao() { 
    DemoDao dao = new DemoDao(); 
    dao.setAddress("annoted:address"); 
    dao.setName("annoted:name"); 
    return dao; 
} 
+1

이것은 받아 들인 응답과 어떻게 다른가요? –

+1

왜 OP가 그렇게해야하는지 설명해야합니다. 또한 더 많은 코드에 대해 의견을 말하면 사람들이 즉시 볼 수 있도록 답변에 넣지 않는 이유는 무엇입니까? :) – LinusGeffarth

+1

방금 ​​한 것과 같이;) –

0

자바 설정에 대해 다음을 사용

@Bean 
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) 
public SpringBean springBean(){ 
    SpringBean bean = new SpringBean(); 
    return bean; 
} 

하거나,

@Scope(value = "prototype") 

를 참조하십시오 @Scope 주석

관련 문제