응용 프로그램 컨텍스트에서 Bean을 추출하려고합니다.응용 프로그램 컨텍스트 bean
그래서 클래스 정의 :
public class ApplicationContextProvider implements ApplicationContextAware {
private static ApplicationContext applicationContext;
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
public void setApplicationContext(ApplicationContext _applicationContext) throws BeansException {
applicationContext = _applicationContext;
}
}
내 applicationContext.xml에 내 코드에서 그러나
<bean id="workflowService" class="com.mycompany.util.WorkflowService">
<bean id="applicationContextProvider" class="com.mycompany.util.ApplicationContextProvider"></bean>
<context:annotation-config />
내가하려고하면
WorkflowService service = (WorkflowService) ApplicationContextProvider.getApplicationContext().getBean("workflowService");
내가 얻을 :
java.lang.ClassCastException가 : $ Proxy40이 com.mycompany.util.WorkflowService
캐스트 할 수없는 편집 :
이WorkflowService 코드 : 나는 WorkflowService
를 추측
public class WorkflowService implements Serializable {
...
@PostConstruct
public void init() {
}
...
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public Collection<lData> findData(Integer contractId) {
}
}
이 하나의 상대 - http://stackoverflow.com/questions/5133291/applicationcontextprovider-is-not-being-called - 나는 당신이 인터페이스 V까지 혼합하고 추측 할 구체적인 클래스를 여러분의 빈에. 정의/참조. WorkflowService 코드를 게시하십시오. –