我在applicaContext.xml中往一个类里注入了属性
<bean id="xxxDao" class="com.xxx.xxx.XxxDao">
   <property name="dataSource">
<ref bean="dataSource" />
</property>
</property>
   </bean >(配置文件里面也有dataSource的bean声明,xxxDao类里也有get set方法)但是在某个测试页面中取出这个属性的时候dataSource总是为空
刚开始爆了空指针异常,然后查到这块,在测试页面我做了判断 xxxDao.getDataSource == null 这个总是true
为什么注入了以后还是空呢我把配置文件改成错的( 将ref=dataSource改成不存在的bean),这时候在部署的时候报错了,说明配置文件解析了
但是改成正确的时候调用到这个类的对象的时候使用注入的属性总是为空
有没有前辈遇到过类似的问题啊!!初学不久还不太熟悉,求解答

解决方案 »

  1.   

     <property name="dataSource">
    <ref bean="dataSource" />改成<property name="dataSourc" ref="dataSource"></property>
    事实
      

  2.   

    先要去顶你的DATASOURE是正确的 可以写个测试类 测试下
    ApplicationContext ctx=new ClassPathXmlApplicationContext("你的SPRING配置文件的路径和文件名");
    DataSource ds=ctx.getBean("dataSource");system.out.pring(ds);看看你DataSource是否配置错误
      

  3.   

    sessionFactory。
    你的dataSource注意下。