热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

autowired注入dao为null

1234567891011121314151617181920212223242526@Component//这里必须有注入才能进来,换成@Service也不好使,我想在应用启动的时候初始化一些东西p

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
@Component//这里必须有注入才能进来,换成@Service也不好使,我想在应用启动的时候初始化一些东西

public class ExceptionCode {



    public static Map map = null;

   

//    public ExceptionCode(){}

   

    @Autowired//这里不知道为什么为null

    private ICmpDao cmpDao;

   

    /**

     * 初始化异常编号

     */

    public ExceptionCode(){

        if(cmpDao == null)

            throw new RuntimeException(" cmpOutDao is null");

        List list =

                cmpDao.searchExceptionCodeList();

        if(list == null || list.size() <= 0)

            throw new RuntimeException(""

                    + " cmp exception code table not data ");

        map = new HashMap();

        for (CmpException ec : list)

            map.put(ec.getCode(),ec.getTmCode());

    }

}

之前在struts2框架下是这么写的好使,但现在代码需要移动到Spring不知道怎么写了,或者我应该怎么改?



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public class ExceptionCode {



    public static Map map = null;

   

    public ExceptionCode(){}

   

    /**

     * 初始化异常编号

     */

    public ExceptionCode(ICmpDao cmpDao){

        if(cmpDao == null)

            throw new RuntimeException(" cmpOutDao is null");

        List list =

                cmpDao.searchExceptionCodeList();

        if(list == null || list.size() <= 0)

            throw new RuntimeException(""

                    + " cmp exception code table not data ");

        map = new HashMap();

        for (CmpException ec : list)

            map.put(ec.getCode(),ec.getTmCode());

    }

}



   



推荐阅读
author-avatar
津城小伙丶Mf
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有