日期:2014-05-18  浏览次数:20649 次

@Autowired 注入对象是NULL
使用的spring MVC 
在Controller PayAction类里面通过反射创建一个对象wzt


public class PaymentAction  
@Autowired
protected MyecService myecService; (不为NULL)

这个类里面有个方法通过反射创建对象 简单工厂方法
Platform platform = Factory.createPlatform(paymentTypeNo);
platform.returnMessageHandle(request, response, paymentTypeNo);

创建的具体是Wzt类的对象
@Service
public class Wzt extends PlatformPayment implements Platform { 
@Autowired
protected MyecService myecService; (NULL)

配置文件自动扫描,wzt在service包下 
<!-- Anontation @Component scan... -->
<context:annotation-config />
<context:component-scan base-package="com.**.action" />
    <context:component-scan base-package="com.**.service.**"/>


求解,为什么Action中的myecService注入了,耳通过创建对象中myecService为NULL呢
------解决方案--------------------
从两点入手判断:
一:看看你的Springmvc配置是否正确;即:其它地方的调用有没有问题,若其他地方也不正常,那你就得好好瞧瞧你的Springmvcd的架构哪里出问题了;(加一句核对你自动扫描的包是否正确。)
二:若盘点Springmvc的配置没有问题,则去查看你service是否注解了,最好能给注解带上name属性;