错误信息如下:
SyllabusService.java 第七十七行如下:输出 jsoupService 的时候显示为NULL
//SyllabusService.java中
        private JsoupService jsoupService;
public JsoupService getJsoupService() {
return jsoupService;
} @Resource(name ="jsoupService")
public void setJsoupService(JsoupService jsoupService) {
this.jsoupService = jsoupService;
}//JsoupService.java中
@Service("jsoupService")
public class JsoupService {
//....
}
其他的对象注入都正常,就jsoupService总是NULL。非常不解。springjava注入

解决方案 »

  1.   

     @Resource(name ="jsoupService")     public void setJsoupService(JsoupService jsoupService) {         this.jsoupService = jsoupService;     }
    楼主测试一下这个方法是否有被执行
      

  2.   

    我把 @Service  改成 @Component("jsoupService")   依然不行啊。
      

  3.   

    其它的注入到service中也没出现这种状况啊。
      

  4.   

    System.out.println(jsoupService)
    查看 此对象存在不。如果存在就说明 返回有问题,检查getsyllabus逻辑。
      

  5.   

    这两个地方输出有值,其他的地方就没有值了。
    public JsoupService getJsoupService() {
                    System.out.println(jsoupService);//这里输出有值
    return jsoupService;
    } @Resource(name ="jsoupService")
    public void setJsoupService(JsoupService jsoupService) {
                    System.out.println(jsoupService);//这里输出有值
    this.jsoupService = jsoupService;
    }
      

  6.   

    你直接调用getJsoupService()方法看看能否正确执行
      

  7.   

     @Resource
      public void setJsoupService(JsoupService jsoupService) {        this.jsoupService = jsoupService;    }这个样子试试
      

  8.   

    检查配置中的
    <context:component-scan/>标签
      

  9.   

    1,你首选得看看,你的每一个组件是不是已经创建好了,用junit去测试一下吧。
    2,你把下面的代码改一改吧。@Resource(name ="jsoupService")
        public void setJsoupService(JsoupService jsoupService) {
                    System.out.println(jsoupService);//这里输出有值
            this.jsoupService = jsoupService;
        }
    为:
    @Resource(name ="jsoupService")
    private JsoupService jsoupService;
    不要用set上面加注解了。
      

  10.   

    <context:annotation-config/>
    <context:component-scan base-package="cn.recx.wechat"/>没错的。
      

  11.   


    用的时候都是NULL。之前没出现这个状况啊。互相关注一下呗。远程帮我看看
      

  12.   

    @Resource
    private JsoupService jsoupService;这个样子看看.
    在不行的话JsoupService就是你这个Service标记的有问题了
      

  13.   

    试过这个了。还是不行,还是NULL。