Changes between Version 4 and Version 5 of youhua/2017_1


Ignore:
Timestamp:
01/17/2017 02:15:55 PM (9 years ago)
Author:
wuyuanbo
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • youhua/2017_1

    v4 v5  
    33 
    44 
    5 在servlet处理请求时,EnvFilter中会调用EnvUtils.getEnv()实例化Env,并对实例进行参数设置,这些都是必要步骤,在非Controller类或jsp中使用EnvUtils.getEnv()可能会跳过这些步骤,从而造成程序出错 
     5在servlet处理请求时,EnvFilter中会调用EnvUtils.getEnv()实例化Env,并对实例进行参数设置,这些都是必要步骤,在使用EnvUtils.getEnv()时如果跳过这些步骤,调用一些需要用到request、response、servletContext的方法时会出现NullPointerException错误 
    66 
    77{{{ 
     
    3333        public UserPurchasingInfo getInfo() { 
    3434                ...... 
    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); 
    3737                ...... 
    3838        } 
     
    4040} 
    4141}}} 
    42 这种代码至少在三种情况下调用会出现NullPointerException错误:[[BR]] 
    43 1.在单元测试中被调用时[[BR]] 
    44 2.不依赖于servlet的定时任务中被调用时[[BR]] 
     42'''这种代码至少在三种情况运行用会出现NullPointerException错误:'''[[BR]] 
     431.在单元测试中运行。[[BR]] 
     442.不依赖于servlet的定时任务中运行。[[BR]] 
    45453.在处理servlet的请求时,通过代码发起的新线程中简单的调用EnvUtils.getEnv().getBean(xxx.class)获取某个类的实例会和1、2点一样出现错误。[[BR]][[BR]] 
    4646 
     
    7373将非Controller的java类中的EnvUtils.getEnv().getBean(GeliDao.class)改为GeliUtils.getDao(),[[BR]] 
    7474将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