首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

求高手,spring3.2+hibernate4.1整合后数据源有关问题

2012-09-25 
求高手,spring3.2+hibernate4.1整合后数据源问题spring配置XML code?xml version1.0 encodingUTF-8

求高手,spring3.2+hibernate4.1整合后数据源问题
spring配置

XML code
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"    xmlns:tx="http://www.springframework.org/schema/tx"    xsi:schemaLocation="http://www.springframework.org/schema/beans                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd                        http://www.springframework.org/schema/tx                        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd                         http://www.springframework.org/schema/aop                        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">    <!-- 配置sessionFactory -->    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">        <property name="configLocation">            <value>classpath:hibernate.cfg.xml</value>        </property>    </bean>    <!-- 配置事务管理器 -->    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">        <property name="sessionFactory">            <ref bean="sessionFactory" />        </property>    </bean>    <!-- 配置事务传播特性 -->    <tx:advice id="txAdvice" transaction-manager="transactionManager">        <tx:attributes>            <tx:method name="add*" propagation="REQUIRED" />            <tx:method name="del*" propagation="REQUIRED" />            <tx:method name="update*" propagation="REQUIRED" />            <tx:method name="*" read-only="true"/>        </tx:attributes>    </tx:advice>    <!-- aop对哪些类的哪些方法实行事务管理 -->    <aop:config>        <aop:pointcut id="allManager" expression="execution(* com.spg.manager.*.*(..))" />        <aop:advisor advice-ref="txAdvice" pointcut-ref="allManager"/>    </aop:config></beans>


hibernate配置
XML code
<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE hibernate-configuration PUBLIC          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools. --><hibernate-configuration>    <session-factory>        <property name="hibernate.dialect">            org.hibernate.dialect.MySQLInnoDBDialect        </property>        <property name="hibernate.connection.url">            jdbc:mysql://localhost/SSH?characterEncoding=UTF-8        </property>        <property name="hibernate.connection.username">root</property>        <property name="hibernate.connection.password">admin</property>        <property name="hibernate.connection.driver_class">            com.mysql.jdbc.Driver        </property>        <property name="hibernate.show_sql">true</property>        <property name="hibernate.hbm2ddl.auto">update</property>        <property name="hibernate.current_session_context_class">thread</property>                <mapping resource="com/spg/bean/User.hbm.xml" />        <mapping resource="com/spg/bean/Log.hbm.xml" />    </session-factory></hibernate-configuration> 


字数超出限制,错误堆栈信息:见一楼


[解决办法]
<property name="hibernate.connection.url">
jdbc:mysql://localhost/SSH?characterEncoding=UTF-8
</property>
--------------------------
这句应该写错了????????????没端口号????????????
[解决办法]
是不是logMrg写错了,应该是logMgr
[解决办法]
没有配置dataSource吗?配置下,然后在事物管理器中再配置下:

XML code
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">        <property name="sessionFactory">            <ref bean="sessionFactory" />        </property>        <property name="dataSource" ref="dataSource"/>    </bean>
[解决办法]
有可能是楼主大意bean写错了:Cannot resolve reference to bean 'logMgr' while setting bean property 'logMrg'
找不到bean 'logMgr' 的属性 'logMrg'
是不是logMgr或logMrg中某个字母不小心站错位置?
[解决办法]
Error creating bean with name 'transactionManager' defined in file [D:\Workspaces\hibernate-spring\bin\applicationContext-common.xml]: Invocation of init method failed; nested exception is org.hibernate.service.UnknownUnwrapTypeException: Cannot unwrap to requested type [javax.sql.DataSource]

----------------------------------
初始化transactionManager时出错了,应该是没法得到javax.sql.DataSource实例!

热点排行