Struts2 Spring 整合, Spring 使用 configLocation属性 联接hibernate.cfg.xml 找到不Action

xiaoxiao2023-01-26  80

在做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的时有个参考,前车之鉴啊。多了解一下报错的原因免得以后碰到类似问题一下子没了头绪。
转载请注明原文地址: https://www.6miu.com/read-4980787.html

最新回复(0)