ServletContext servletContext = request.getSession().getServletContext();
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext );
WhatBean whatBean = (WhatBean )ctx.getBean( "what"); 
本文介绍了一种通过ServletContext从Spring容器中获取Bean实例的方法。具体步骤包括:首先利用HttpServletRequest对象获取到ServletContext,然后通过WebApplicationContextUtils工具类从ServletContext中获得WebApplicationContext,最后通过此ApplicationContext对象获取所需的Bean实例。
ServletContext servletContext = request.getSession().getServletContext();
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext );
WhatBean whatBean = (WhatBean )ctx.getBean( "what"); 
1390

被折叠的 条评论
为什么被折叠?