Struts2 Spring 整合, Spring 使用 configLocation属性 联接hibernate.cfg.xml 找到不Action
2009-09-26 01:55
976 查看
在做Struts2 Spring Hibernate整合的时候遇到个问题:
用Spring去管理所有的action时运行编译时总是报找不到某个action。当然这个问题的可能有好多种比如:没有引入struts2-spring-plugin-x.x.jar包、没有在web.xml中添加listener、以有可能在web.xml中没有指定对Spring配置文件的路径等。而我出的问题不在这几种可能的范围内。
我在Spring配置文件中定义sessionFactory是这么定义的:
<bean id="dataSource" destroy-method="close" class="com.mchange.v2.c3p0.ComboPooledDataSource">
……
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>cn/haoyk/cms/model/User.hbm.xml</value>
……
</list>
</property>
……
</bean>
后来改为configLocation方式联接hibernate.cfg.xml配置文件如下:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
则报错找不到某个action,就如我上一篇文章(Unable to instantiate default tuplizer 错误)的错误一样,发现原来是hibernate.cfg.xml中指定mapping resource 的一个.hbm.xml文件配置出错了。而刚好上一种方法中忘记指定那个配置错误的.hbm.xml文件了。到这里终于找到问题出在哪了。
原来问题不出在Spring用configLocation指定hibernate.cfg.xml文件上。而是指的hibernate.cfg.xml中一个.hbm.xml文件配置出错导致找不到Action。所以希望大家在做SSH整合时出现类似找不到action的时有个参考,前车之鉴啊。多了解一下报错的原因免得以后碰到类似问题一下子没了头绪。
用Spring去管理所有的action时运行编译时总是报找不到某个action。当然这个问题的可能有好多种比如:没有引入struts2-spring-plugin-x.x.jar包、没有在web.xml中添加listener、以有可能在web.xml中没有指定对Spring配置文件的路径等。而我出的问题不在这几种可能的范围内。
我在Spring配置文件中定义sessionFactory是这么定义的:
<bean id="dataSource" destroy-method="close" class="com.mchange.v2.c3p0.ComboPooledDataSource">
……
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>cn/haoyk/cms/model/User.hbm.xml</value>
……
</list>
</property>
……
</bean>
后来改为configLocation方式联接hibernate.cfg.xml配置文件如下:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
则报错找不到某个action,就如我上一篇文章(Unable to instantiate default tuplizer 错误)的错误一样,发现原来是hibernate.cfg.xml中指定mapping resource 的一个.hbm.xml文件配置出错了。而刚好上一种方法中忘记指定那个配置错误的.hbm.xml文件了。到这里终于找到问题出在哪了。
原来问题不出在Spring用configLocation指定hibernate.cfg.xml文件上。而是指的hibernate.cfg.xml中一个.hbm.xml文件配置出错导致找不到Action。所以希望大家在做SSH整合时出现类似找不到action的时有个参考,前车之鉴啊。多了解一下报错的原因免得以后碰到类似问题一下子没了头绪。
相关文章推荐
- Spring整合hibernate的事务属性介绍以及声明式事务管理 (使用Annotation和xml)
- Spring整合Hibernate配置(使用hibernate.cfg.xml文件)
- Spring整合Hibernate的时候使用hibernate.cfg.xml
- Spring整合Hibernate的时候使用hibernate.cfg.xml
- Spring整合hibernate的事务属性介绍以及声明式事务管理 (使用Annotation和xml)
- Spring整合hibernate的事务属性介绍以及声明式事务管理 (使用Annotation和xml)
- Spring整合Hibernate的时候使用hibernate.cfg.xml的区别
- Spring整合Hibernate配置(使用hibernate.cfg.xml文件)
- struts2,hibernate,spring三大框架整合的注册程序(xml 配置,mysql数据库)
- spring与jpa整合 简化persistence.xml配置文件 使用属性文件 数据源dbcp访问数据库
- 在VS2008中使用Nhibernate单元测试时无法找到hibernate.cfg.xml文件的解决方案
- Spring整合hibernate:3、使用XML进行声明式的事务管理
- Struts2、Hibernate、Spring整合时如何向Servlet注入属性
- Spring3.x_Struts2.x_Hibernate3.x整合之分页pager-taglib的简单使用
- spring整合hibernate(无hibernate.cfg.xml)
- Spring2.5整合Hibernate3.0中使用XML以tx来配置事务管理。
- 注解的力量 -----Spring 2.5 JPA hibernate 使用方法的点滴整理(二):进一步消除 hibernate.cfg.xml
- SSH整合时不使用hibernate.cfg.xml
- ssh整合思想 Spring与Hibernate和Struts2的action整合 调用action添加数据库 使用HibernateTemplate的save(entity)方法
- 注解的力量 -----Spring 2.5 JPA hibernate 使用方法的点滴整理(二):进一步消除 hibernate.cfg.xml