当前位置:Gxlcms > 数据库问题 > Java在项目启动时访问数据库,在ServletContextListener解决对象无法注入问题

Java在项目启动时访问数据库,在ServletContextListener解决对象无法注入问题

时间:2021-07-01 10:21:17 帮助过:76人阅读

logInfoServiceProxy;

@Override
public void contextInitialized(ServletContextEvent event) {

  WebApplicationContext context = WebApplicationContextUtils
  .getRequiredWebApplicationContext(event.getServletContext());
  logInfoServiceProxy = (LogInfoServiceIFC) context.getBean("logInfoService");

}

 

2、SpringMVC项目可直接在类中加入下面这句话:

SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);

 

被坑了好几次

 

Java在项目启动时访问数据库,在ServletContextListener解决对象无法注入问题

标签:util   ext   web   解决   init   roc   require   lis   nba   

人气教程排行