bang0306 2016-06-24 14:58 采纳率: 0%
浏览 1387

spring+struts2 启动注入bean成功,运行中bean为null

web.xml


contextConfigLocation
classpath:applicationContext.xml


org.springframework.web.context.ContextLoaderListener

applicationContext.xml

<bean id="tangService" class="com.bander.service.TangService"
          p:dao-ref="tangDao"/>
    <bean id="tangDao" class="com.bander.dao.TangDAO"
          p:sessionFactory-ref="sessionFactory"/>
    <bean id="searchAction" class="com.bander.action.SearchAction" p:service-ref="tangService"/>

已确认在所有引用bean的类中都有setter和getter,在junit中测试是没有问题的,测试代码如下


 @Test
public void testService(){
    ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    SearchAction action = context.getBean("searchAction", SearchAction.class);
    PageModel<PoetryBlock> pm = action.getService().searchPoet("李白",1,10);
    List<PoetryBlock> pbs = pm.getDatas();
    for(PoetryBlock pb : pbs){
        System.out.println(pb.getTitle());
    }
}
所以推测是不是我的监听器配得有问题,以至于在web环境下无法使用spring管理bean,大神们帮我看看






  • 写回答

2条回答 默认 最新

  • bang0306 2016-06-24 15:00
    关注

    好吧,第一次发帖有点儿乱

    web.xml

     <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext.xml</param-value>
        </context-param>
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?