<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
解决方案 »
- java测试题 跪求解答!!
- 梅花日历控件在ASP.net中如何实现?
- 老鸟推荐几本struts hibernate spring 的书
- javax.servlet.ServletException:
- JAVA 斑马打印!急!~~~
- XP系统是不是不支持JDBC和ODBC驱动程序访问SQL
- 求一struts+spring+ibatis的例子。。。
- 数据库死锁问题
- 请教CITRIX是什么开发工具,AIX5.2是什么操作系统???
- 电子商务毕业设计,烟草网上订货是否可实现?
- mvc模式的理解?
- struts2.0.11+spring2.5.3+hibernate3.2.6不能连接oracle10G数据库案例及解决办法
我别的注入都成功了,区别就是成功的是把它注入到action里面了,这个注入到listener里就不行 了,我打印了要注入的对象,是null的
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- Moudle 层配置 -->
<bean id="customerDao" class="last.soul.dao.impl.CustomerDaoImpl">
</bean>
<bean id="orderDao" class="last.soul.dao.impl.OrderDaoImpl"></bean><!-- Service 层配置 -->
<bean id="customerService" class="last.soul.service.impl.CustomerServiceImpl">
<property name="customerDao">
<ref local="customerDao"></ref>
</property>
</bean>
<bean id="orderService" class="last.soul.service.impl.OrderServiceImpl">
<property name="orderDao">
<ref local="orderDao"></ref>
</property>
</bean>
<!-- Web 层配置 -->
<bean id="RegisterAction" class="last.soul.web.RegisterAction" scope="prototype">
<property name="customerService">
<ref local="customerService"/>
</property>
</bean>
<bean id="LoginAction" class="last.soul.web.LoginAction" scope="prototype">
<property name="customerService">
<ref local="customerService"></ref>
</property>
</bean></beans>上这这个是我的applicationContext.xml.package last.soul.web;
import java.util.Map;import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;import last.soul.bean.Book;
import last.soul.common.BeanFactory;
import last.soul.common.exception.OrderServiceException;
import last.soul.service.IOrderService;public class ContextListener implements ServletContextListener { public void contextDestroyed(ServletContextEvent arg0) {
// TODO Auto-generated method stub
ServletContext stx = arg0.getServletContext();
stx.removeAttribute("books");
} public void contextInitialized(ServletContextEvent arg0) {
// TODO Auto-generated method stub
ServletContext stx = arg0.getServletContext();
IOrderService orderService =
(IOrderService)BeanFactory.getBean("orderService");
try {
Map<Long,Book> books =orderService.listAllBook();//调用orderService的方法
System.out.println(books+"in listenter");
stx.setAttribute("books", "booksdd");
} catch (OrderServiceException e) {
e.printStackTrace();
}
}}这是我的Listener代码。我的web层的两个action调用customerService,customerService调用customerDao都没问题
当我在Listener里面调用orderService时候也是成功的(没有用spring注入),orderService里面我注入了orderDao
代码如上所示,在orderServiceImpl中打印orderDao对象为null。
问题在哪里,各位指点一下,莫非Listener有什么说法,和applicationContext.xml加载的先后有关吗?applicationContext.xml它是什么时候加载的?
Srervice service = (Service)srpingCtx.getBean("Service");