java spring 反射调用方法参数_利用java的反射机制动态调用类方法,在被调用的类中获取spring的BO,为什么BO无法实例化?...

在Java应用中,通过反射调用`test`类的方法时,尝试从Spring上下文中获取并实例化BO,但发现`SpringContextUtil`的`applicationContext`为null,导致无法正常实例化BO。问题可能源于Spring上下文未正确初始化或`SpringContextUtil`的静态变量访问时机不当。解决方案可能包括确保在调用反射方法前完成Spring的初始化或采用其他方式注入BO。
摘要由CSDN通过智能技术生成

客户端调用webservice里面的doInsertUralOper方法,在doInsertUralOper中根据传入参数的不同,利用java反射机制,调用test类,在test里面调用BO,BO里调用了DAO~BO的配置文件如下:

客户端调用webservice里面的doInsertUralOper 方法,

在doInsertUralOper 中根据传入参数的不同,利用java反射机制,调用test类,在test里面调用BO,BO里调用了DAO~

BO的配置文件如下:

test类方法:

public void test(String paraStr){

IUralOperBO uralOperBO = (IUralOperBO) SpringContextUtil.getBean("uralOperBOAction");

try {

uralOperBO.test(paraStr);

} catch (ServiceException e) {

e.printStackTrace();

}

}

SpringContextUtil类

public class SpringContextUtil implements ApplicationContextAware {

public SpringContextUtil() {

}

public void setApplicationContext(ApplicationContext applicationContext)

throws BeansException {

applicationContext = applicationContext;

}

public static ApplicationContext getApplicationContext() {

return applicationContext;

}

public static Object getBean(String name) throws BeansException {

return applicationContext.getBean(name);

}

…………

private static ApplicationContext applicationContext;

}

现在能够反射到test类,但是在test里面不能将BO实例化,而且获取不到spring的上下文,SpringContextUtil中的applicationContext为null,求问题原因和解决办法。

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值