我无法在服务层获取spring bean(ServiceContext.getBean(“beanName”))。我能够在servlet中获得bean。我在下一节课中做错了什么?如何从服务层访问弹簧管理的bean
package com.ekaplus.presentation.common;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
public class ServiceContext implements ApplicationContextAware{
private static ApplicationContext applicationContext;
@SuppressWarnings("static-access")
public void setApplicationContext(ApplicationContext ctx)throws BeansException {
this.applicationContext=ctx;
}
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
public static Object getBean(String beanName)
{
return applicationContext.getBean(beanName);
}
}
有没有例外? – 2010-11-01 07:09:58