qq_23437891
fcoolish
2017-06-07 13:09

服务器报错无法创建sessionFactory对象,但是配置是正确的,求教

  • tomcat
  • 服务器
  • mvc
  • java-ee
  • eclipse

这是applicationContext.xml的配置
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
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/aop http://www.springframework.org/schema/aop/spring-aop-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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- 导入外部的properties配置文件 -->

<!-- 配置c3p0数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="jdbcUrl" value="${jdbcUrl}"></property>
    <property name="driverClass" value="${driverClass}"></property>
    <property name="user" value="${user}"></property>
    <property name="password" value="${password}"></property>
    <!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
    <property name="initialPoolSize" value="${initialPoolSize}"></property>
    <!--连接池中保留的最小连接数。Default: 3 -->
    <property name="minPoolSize" value="3"></property>
    <!--连接池中保留的最大连接数。Default: 15 -->
    <property name="maxPoolSize" value="${maxPoolSize}"></property>
    <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
    <property name="acquireIncrement" value="3"></property>
    <!--最大空闲时间,1800秒内未使用则连接被丢弃,若为0则永不丢弃。Default: 0 -->
    <property name="maxIdleTime" value="1800"></property>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"></property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="javax.persistence.validation.mode">none</prop>
        </props>
    </property>
    <property name="mappingLocations">
        <list>
            <value>classpath:cn/tax/nsfw/*/entity/*.hbm.xml</value>
            <value>classpath:cn/tax/test/entity/*.hbm.xml</value>
        </list>
    </property>
</bean>

<!-- 事务管理 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- 事务通知 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
    <tx:attributes>
        <tx:method name="find*" read-only="true"/>
        <tx:method name="get*" read-only="true"/>
        <tx:method name="list*" read-only="true"/>
        <tx:method name="*" rollback-for="Throwable"/>
    </tx:attributes>
</tx:advice>

<!-- aop配置被事务控制的类 -->
<aop:config>
    <aop:pointcut id="serviceOperation" expression="bean(*Service)"/><!-- 扫描以Service结尾的bean -->
    <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation"/>
</aop:config>

<!-- 所有业务dao的parent -->
<bean id="baseDao" abstract="true">
    <property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- 引入外部sprign配置文件 -->
<import resource="classpath:cn/tax/*/conf/*-spring.xml"/>
<import resource="classpath:cn/tax/nsfw/*/conf/*-spring.xml"/>



  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答

为你推荐

换一换