springMvc中获取spring中的bean

yadg yadg 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我有个类,web.xml 配置
<servlet>
<servlet-name>vdc_ui</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext-servlet.xml</param-value>
<load-on-startup>1</load-on-startup>
</init-param>
</servlet>
applicationContext-servlet.xml中,配置了一个bean,这个bean
<bean id="testA" class="com.bb.testA"></bean>

在controllerer中的某个方法里,使用下面的代码获取:
WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
service=(LogInjectionSaf)webApplicationContextgetBean("testA");
为什么显示 service为null呢,怎么才能得到?
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
yadg
Java EE 67,535 成员 225,843 内容