作者:津城小伙丶Mf | 来源:互联网 | 2023-08-20 22:09
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());
}
} |