解决方案 »

  1.   

    XML配置有问题,先把里面所有其他的bean去掉,一个一个的看。
      

  2.   

    贴出applicationContext.xml文件的全部内容看看
      

  3.   

    注入baseDaoImpl时失败,,  看下这个bean是在哪里进行注入的,这个bean有没有在配制文件中写出来,如果是用注解的话可以看下注解是否写错了。最好贴代码出来。
      

  4.   

    <?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:p="http://www.springframework.org/schema/p" 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-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
        
        <!-- 说明:下面有的Bean配置提供了多种方案,请根据需要采用某一种(别忘了注释掉其他同类方案) --> <!-- 自动扫描Spring注解配置 -->
    <context:component-scan base-package="com" /> <!-- 自动加载属性配置文件 -->
    <context:property-placeholder location="classpath:jdbc.properties" />

    <!-- 配置数据源:方法一,使用C3P0方式(推荐) -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" 
    destroy-method="close" 
    p:driverClass="${jdbc.driverClassName}"
    p:jdbcUrl="${jdbc.url}" 
    p:user="${jdbc.username}" 
    p:password="${jdbc.password}" /> <!-- 配置数据源:方法二,使用DBCP方式(不推荐) -->
    <!-- 
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
    destroy-method="close" 
    p:driverClassName="${jdbc.driverClassName}" 
    p:url="${jdbc.url}" 
    p:username="${jdbc.username}" 
    p:password="${jdbc.password}" />
     --> <!-- 配置数据源:方法三,使用JNDI方式 -->
    <!-- 
    <jee:jndi-lookup id="dataSource" jndi-name="${jndi.name}" />
     -->
     
    <!-- 配置Hibernate的数据源代理工厂:方法一,使用p属性通配符,按文件名搜索匹配的映射文件 -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
    p:dataSource-ref="dataSource" p:mappingLocations="classpath*:/com/sqjzws/domain/*.hbm.xml">
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
    <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
    <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
    <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
    <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
    <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
    <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
    </props>
    </property>
    </bean>
    <!-- 配置Hibernate的数据源代理工厂:方法二,使用list集合,按文件名搜索匹配的映射文件 -->
    <!-- 
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
    p:dataSource-ref="dataSource">
    <property name="mappingLocations">
    <list>
    <value>classpath*:/com/**/*.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
    <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
    <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
    <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
    <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
    <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
    <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
    </props>
    </property>
    </bean>
     -->
    <!-- 配置Hibernate的数据源代理工厂:方法三,使用p属性通配符,按目录搜索映射文件 -->
    <!-- 
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
    p:dataSource-ref="dataSource" p:mappingDirectoryLocations="classpath*:/com/**/domain">
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
    <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
    <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
    <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
    <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
    <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
    <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
    </props>
    </property>
    </bean>
     -->
    <!-- 配置Hibernate的数据源代理工厂:方法四,使用hibernate.cfg.xml -->
    <!-- 
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
    p:dataSource-ref="dataSource" p:configLocation="classpath:hibernate.cfg.xml">
    </bean>
     -->
     
      <!-- 配置事务管理器 -->
    <bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager"
    p:sessionFactory-ref="sessionFactory" />
    <!-- 配置声明式事务:方法一,在Service实现类或者public实现方法上使用注解@Transactional,则此类或方法就会启用事务机制 -->
    <tx:annotation-driven transaction-manager="transactionManager" /> <!-- 配置声明式事务:方法二,使用tx/aop命名空间的配置(其实还有方法三,由于快要过时不推荐使用了,这里就不给出方法三的配置了) -->
    <!-- 
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
    <tx:method name="insert*" propagation="REQUIRED" />
    <tx:method name="update*" propagation="REQUIRED" />
    <tx:method name="edit*" propagation="REQUIRED" />
    <tx:method name="save*" propagation="REQUIRED" />
    <tx:method name="add*" propagation="REQUIRED" />
    <tx:method name="new*" propagation="REQUIRED" />
    <tx:method name="set*" propagation="REQUIRED" />
    <tx:method name="remove*" propagation="REQUIRED" />
    <tx:method name="delete*" propagation="REQUIRED" />
    <tx:method name="change*" propagation="REQUIRED" />
    <tx:method name="get*" propagation="REQUIRED" read-only="true" />
    <tx:method name="find*" propagation="REQUIRED" read-only="true" />
    <tx:method name="load*" propagation="REQUIRED" read-only="true" />
    <tx:method name="search*" propagation="REQUIRED" read-only="true" />
    <tx:method name="*" propagation="REQUIRED" read-only="true" />
    </tx:attributes>
    </tx:advice>
    <aop:config>
    <aop:pointcut id="mypointcut" expression="execution(* com.**.service..*.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="mypointcut" />
    </aop:config>
     -->
     
     

    <!-- 下面三个Bean的配置可有可无,但配置后用处更大,通常用于BaseDao类、其他Dao类或特殊工具类中 -->
    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate"
    p:sessionFactory-ref="sessionFactory" />

    <bean id="hibernateDaoSupport" class="org.springframework.orm.hibernate4.support.HibernateDaoSupport"
    p:hibernateTemplate-ref="hibernateTemplate" abstract="true"/>

    <bean id="sessionFactoryUtils" class="org.springframework.orm.hibernate4.SessionFactoryUtils" abstract="true"/>

    </beans>