Changes between Version 4 and Version 5 of youhua/2017_1
- Timestamp:
- 01/17/2017 02:15:55 PM (9 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
youhua/2017_1
v4 v5 3 3 4 4 5 在servlet处理请求时,EnvFilter中会调用EnvUtils.getEnv()实例化Env,并对实例进行参数设置,这些都是必要步骤,在 非Controller类或jsp中使用EnvUtils.getEnv()可能会跳过这些步骤,从而造成程序出错。5 在servlet处理请求时,EnvFilter中会调用EnvUtils.getEnv()实例化Env,并对实例进行参数设置,这些都是必要步骤,在使用EnvUtils.getEnv()时如果跳过这些步骤,调用一些需要用到request、response、servletContext的方法时会出现NullPointerException错误。 6 6 7 7 {{{ … … 33 33 public UserPurchasingInfo getInfo() { 34 34 ...... 35 info = EnvUtils.getEnv().getBean(GeliDao.class).find(UserPurchasingInfo.class, this.userId);36 //或者 info = EnvUtils.getEnv().getBean(UserPurchasingInfoService.class).find(this.userId);35 UserPurchasingInfo info = EnvUtils.getEnv().getBean(GeliDao.class).find(UserPurchasingInfo.class, this.userId); 36 //或者 UserPurchasingInfo info = EnvUtils.getEnv().getBean(UserPurchasingInfoService.class).find(this.userId); 37 37 ...... 38 38 } … … 40 40 } 41 41 }}} 42 这种代码至少在三种情况下调用会出现NullPointerException错误:[[BR]]43 1.在单元测试中 被调用时[[BR]]44 2.不依赖于servlet的定时任务中 被调用时[[BR]]42 '''这种代码至少在三种情况运行用会出现NullPointerException错误:'''[[BR]] 43 1.在单元测试中运行。[[BR]] 44 2.不依赖于servlet的定时任务中运行。[[BR]] 45 45 3.在处理servlet的请求时,通过代码发起的新线程中简单的调用EnvUtils.getEnv().getBean(xxx.class)获取某个类的实例会和1、2点一样出现错误。[[BR]][[BR]] 46 46 … … 73 73 将非Controller的java类中的EnvUtils.getEnv().getBean(GeliDao.class)改为GeliUtils.getDao(),[[BR]] 74 74 将EnvUtils.getEnv().getBean(xxxService.class)改为SpringCtxUtils.getBean(xxxService.class)。(SpringCtxUtils在cn.pconline.best.util目录下) 75 76 == 2.异常处理优化 == 77 78 项目中经常有异常被捕获后没有日志也没有打印,如果在程序执行过程中出现问题,不容定位到。 79 80 {{{ 81 private String getMoreTopicText(long topicId, int type) { 82 try { 83 ...... 84 } catch (Exception e) { 85 } 86 return ""; 87 } 88 }}} 89 90
![(please configure the [header_logo] section in trac.ini)](http://www1.pconline.com.cn/hr/2009/global/images/logo.gif)