如题所述,得不到bean
具体的操作如下,我的前端是用DWR的
在tomcat服务器启动的时候自动加载spring配置文件
web.xml的配置如下:
<!-- 载入Spring配置文件--> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:/applicationContext_hibernate.xml</param-value> <!-- 自动载入的spring配置 --> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
    
spring配置文件中有要获取的这个ID的bean
我在action中要获取applicationContex实例来获取spring配置文件中的bean,写法如下:
ServletContext servletContext = WebContextFactory.get().getSession().getServletContext(); ApplicationContext ctx=WebApplicationContextUtils.getWebApplicationContext(servletContext); iaduserInfoService=(IaduserInfoService)ctx.getBean("aduserInfoService");    
运行的时候问题出来了,页面提示“No bean named 'aduserInfoService' is defined”即aduserInfoService这个bean没有被找到。。可明明spring配置文件也被加载了,然后里面也有个 aduserInfoService为ID的bean,为什么加载不了呢?
我自己的初步预料可能会是因为ServletContext servletContext = WebContextFactory.get().getSession().getServletContext();
ApplicationContext ctx=WebApplicationContextUtils.getWebApplicationContext(servletContext);ctx对象没有被获取到,因为我前端程序是直接用DWR来调用服务器端的action的,action不在spring容器的管理范围内。不知道是不是这样的,各位大虾有遇到这个问题的帮我解答下了。。谢谢