Tomcat启动后,从spring容器中获取Bean和ServletContext

public static Object getBean(String beanName){
       ApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
        return context.getBean(beanName);       
}

public static ServletContext getServletContext(){
   WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
    return context.getServletContext();   
}

 

你可能感兴趣的:(Tomcat启动后,从spring容器中获取Bean和ServletContext)