如题所述,得不到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容器的管理范围内。不知道是不是这样的,各位大虾有遇到这个问题的帮我解答下了。。谢谢
具体的操作如下,我的前端是用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容器的管理范围内。不知道是不是这样的,各位大虾有遇到这个问题的帮我解答下了。。谢谢
解决方案 »
- j2ee中的2什么意思
- 为什么捕获不到NullPointerException异常?下面有代码和一部分异常信息,我做的是oracle和java的编程
- 这种应用场景如何考虑使用什么设计模式来实现?
- 前面加constraint什么意思
- hibernate关于持久化对象的异常
- textarea 怎么才能把换行符传进服务器呀
- [求助]用hibernate插入表单数据报错..
- 告诉我为什么!
- j2ee 的架构里面可不可以调用VC生成的DLL?
- ejb已经在服务器上配置好,请问,一个普通的java application如何访问它?
- weblogic8.1在myeclipse上启动出现下面异常
- 求个解决数据段交叉的方案
<servlet>
<servlet-name>dwr</servlet-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/classes/prordconfig/dwr.xml</param-value>
</init-param>
</servlet>