解决方案 »

  1.   

    applicationContext.xml配置文件里面是不是配错了
      

  2.   

    <?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: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.2.xsd
                http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
                http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-3.2.xsd">
    <!--配置文件导入 -->
    <import resource="classpath:applicationContext-ehcache.xml"/>
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
    <value>classpath:dataSource.properties</value>
    </property>
    </bean>
    <!--数据源 -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${mssql.database.driver}"></property>
    <property name="url" value="${mssql.database.url}"></property>
    <property name="username" value="${mssql.database.user}"></property>
    <property name="password" value="${mssql.database.password}"></property>
    <property name="maxActive" value="${mssql.database.maxActive}"></property>
    <property name="maxIdle" value="${mssql.database.maxIdle}"></property>
    <property name="maxWait" value="${mssql.database.maxWait}"></property>
    </bean>
    <!--session工厂,里面可以配置Hibernate的映射文件,使用annotatedClasses-->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" >
    <property name="dataSource">
    <ref bean="dataSource" />
    </property>
    <property name="hibernateProperties">
    <value>
            hibernate.dialect=${hibernate.dialect}
    hibernate.hbm2ddl.auto=${hibernate.hbm2ddl.auto}
    hibernate.show_sql=${hibernate.show_sql}
    hibernate.format_sql=${hibernate.format_sql}
    hibernate.cache.use_second_level_cache=${hibernate.cache.use_second_level_cache}
    hibernate.cache.provider_class=${hibernate.cache.provider_class}
    hibernate.cache.use_query_cache=${hibernate.cache.use_query_cache}
    hibernate.jdbc.fetch_size=${hibernate.jdbc.fetch_size}
    hibernate.jdbc.batch_size=${hibernate.jdbc.batch_size}
    hibernate.cache.provider_configuration_file_resource_path=${hibernate.cache.provider_configuration_file_resource_path}
    </value>
    <!-- <props>
    hibernate的方言,建议改成MySQL5Dialect
    <prop key="hibernate.dialect">
    org.hibernate.dialect.MySQL5Dialect
    </prop>
    开发的时候尽量打开true
    <prop key="hibernate.show_sql">false</prop>
    </props>
    -->
    </property>
    <!--  
            <property name="hibernate.cache.provider_class"> net.sf.ehcache.hibernate.EhCacheProvider</property> 指定cache实现类   
            <property name="cache.use_second_level_cache">true</property> 启用二级缓存
            <property name="hibernate.cache.use_query_cache">true</property> 启用查询缓存 
            <property name="hibernate.cache.provider_configuration_file_resource_path">ehcache2.xml</property>//指定ehcache配置文件  
            -->
    <!--主键Bean类-->
    <property name="annotatedClasses">
    <list> 
    <value>com.org.entity.WsUsers</value> 
    <value>com.org.entity.SysUsers</value> 
    <value>com.org.entity.ShopApp</value> 
    <value>com.org.entity.Category</value> 
    <value>com.org.entity.Role</value> 
    <value>com.org.entity.Class</value> 
    <value>com.org.entity.WeixXinKeyword</value> 
    <value>com.org.entity.Goods</value> 
    <value>com.org.entity.Goods_brand</value> 
    <value>com.org.entity.Goods_cate</value> 
    <value>com.org.entity.Goods_Order</value> 
    <value>com.org.entity.Goods_Order_Detail</value> 
    <value>com.org.entity.Goods_Img</value> 
    <value>com.org.entity.Ads</value> 
    <value>com.org.entity.Delivery</value> 
    <value>com.org.entity.Alipay</value> 
    <value>com.org.entity.User_Address</value> 
    <value>com.org.entity.Shop_Address</value> 
    <value>com.org.entity.Setting</value>  
    <value>com.org.entity.Alipay</value>  
    <value>com.org.entity.SysConfig</value>  
    <value>com.org.entity.App_subassembly</value>  
    <value>com.org.entity.App_skin</value>  
    <value>com.org.entity.App_Dev_Plan</value>  
    <value>com.org.entity.App_Dev_Menu</value>  
    <value>com.org.entity.App_Dev_Demand</value>  
    <value>com.org.entity.App_Dev_CheckAccept</value>  
    <value>com.org.entity.App_Dev_Assess</value>  
    </list>
    </property>
    </bean>
    <!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <!-- 配置事务的传播特性 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
    <tx:method name="save*" propagation="REQUIRED" />
    <tx:method name="update*" propagation="REQUIRED" />
    <tx:method name="delete*" propagation="REQUIRED" />
    <tx:method name="*" read-only="true" />
    </tx:attributes>
    </tx:advice>
    <!-- 那些类的哪些方法参与事务 -->
    <aop:config>
    <!--<aop:pointcut id="allServiceMethod" expression="execution(* com.org.core.dao.*.*.*(..))" /> -->
    <aop:pointcut id="allServiceMethod"  expression="execution(* *.service.*(..))" /> 
    <aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice" />
    </aop:config>
    <!-- 使Spring关注Annotation -->
    <context:annotation-config />
    <!-- 让Spring通过自动扫描来查询和管理Bean -->
    <context:component-scan base-package="com.org" />
    <bean id="springUtil" class="com.org.core.utils.SpringUtil" lazy-init="false" />
    <bean id="jacksonObjectMapper" class="org.codehaus.jackson.map.ObjectMapper" lazy-init="false" />
    </beans>
      

  3.   

    Dao的实现类里的sessionFactory是不是没有注进去阿?