打印service初始化mapper日志

This commit is contained in:
shuzheng 2017-01-07 22:13:56 +08:00
parent 8417f2521f
commit 1b89d1a4bf
2 changed files with 14 additions and 8 deletions

View File

@ -20,19 +20,22 @@ public class ApplicationContextListener implements ApplicationListener<ContextRe
@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
// root application context
if(null == contextRefreshedEvent.getApplicationContext().getParent()) {
_log.info(">>>>> spring初始化完毕");
if (null == contextRefreshedEvent.getApplicationContext().getParent()) {
_log.info(">>>>> spring初始化完毕 <<<<<");
// spring初始化完毕后通过反射调用所有service的initMapper方法
Map<String, Object> services = contextRefreshedEvent.getApplicationContext().getBeansWithAnnotation(Service.class);
for(Object service : services.values()) {
_log.info("===== 开始初始化service的initMapper方法 =====");
for (Object service : services.values()) {
_log.info(">>>>> {}.initMapper()", service.getClass().getName());
try {
Method initMapper = service.getClass().getDeclaredMethod("initMapper");
Method initMapper = service.getClass().getMethod("initMapper");
initMapper.invoke(service);
} catch (Exception e) {
_log.error("初始化service的initMapper方法异常", e);
e.printStackTrace();
}
}
_log.info(">>>>> 初始化完成service的initMapper方法");
_log.info("===== 完成初始化service的initMapper方法 =====");
}
}

View File

@ -21,18 +21,21 @@ public class ApplicationContextListener implements ApplicationListener<ContextRe
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
// root application context
if(null == contextRefreshedEvent.getApplicationContext().getParent()) {
_log.info(">>>>> spring初始化完毕");
_log.info(">>>>> spring初始化完毕 <<<<<");
// spring初始化完毕后通过反射调用所有service的initMapper方法
Map<String, Object> services = contextRefreshedEvent.getApplicationContext().getBeansWithAnnotation(Service.class);
_log.info("===== 开始初始化service的initMapper方法 =====");
for(Object service : services.values()) {
_log.info(">>>>> {}.initMapper()", service.getClass().getName());
try {
Method initMapper = service.getClass().getDeclaredMethod("initMapper");
Method initMapper = service.getClass().getMethod("initMapper");
initMapper.invoke(service);
} catch (Exception e) {
_log.error("初始化service的initMapper方法异常", e);
e.printStackTrace();
}
}
_log.info(">>>>> 初始化完成service的initMapper方法");
_log.info("===== 完成初始化service的initMapper方法 =====");
}
}