我想從應用程序上下文中提取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
EDITED:
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具體類在bean。定義/引用。請發佈WorkflowService的代碼。 – 2011-03-07 21:00:34