Spring中获取bean的方式

来源:互联网 发布:淘宝官方自营店是什么 编辑:程序博客网 时间:2024/06/07 00:02

Spring中获取bean的方式

很多时候我们希望将某些公共配置信息写到一个类中,供其他类使用,例如mongo,solr连接,但又不想在spring配置文件中进行注入,希望直接在类中获取类的实例,解决办法详见如下:

import org.springframework.web.context.ContextLoader...WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();wac.getBean(beanID);...
原创粉丝点击