我想从应用程序上下文中提取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