你注入的值有问题,你好好检查下。不行你把你的配置都贴出来,那就可以找到原因。要不你参考一下,
http://www.cnweblog.com/kestrel/archive/2006/04/05/95957.html
这个,然后好好理解一下。

解决方案 »

  1.   

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><!--通过spring的配置文件
        1。 减少了多个配置文件对于调动的干扰
        2。 充分利用框架里面的代码实现对于数据库的基本连接(JDBC或者是HIBERNATE等ORM的连接)。
        3。 充分利用SPRING自带的事务管理机制来确保连接时候的事务处理
     -->
     <!--
      - Application context definition 项目文档注释开头部分 (这个是针对Hibernate的)
      -->
    <beans>
        <!-- ========================= RESOURCE DEFINITIONS ========================= -->
        <!-- Configurer that replaces ${...} placeholders with values from a properties file -->
    <!-- (in this case, JDBC-related settings for the dataSource definition below) -->
    <!-- 如果配置文件放在properties文件里面 
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/jdbc.properties"/>
    </bean>
    -->

    <!-- Local DataSource that works in any environment -->
    <!-- Note that DriverManagerDataSource does not pool; it is not intended for production -->
    <!-- See JPetStore for an example of using Commons DBCP BasicDataSource as alternative -->
    <!-- See Image Database for an example of using C3P0 ComboPooledDataSource as alternative -->
        <!--DataSource definition --> 
        <!--DataSource Connection based on spring itself-->
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.gjt.mm.mysql.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/security"/>
    <property name="username" value="root"/>
    <property name="password" value="zbw2006"/>
    </bean>
    <!--DataSource connection based on apache iteself-->
        <!--
    <bean id = "dataSource"
          class ="org.apache.commons.dbcp.BasicDataSource">    
          <property name="driverClassName">
             <value>org.gjt.mm.mysql.Driver</value>
          </property>       
         
          <property name ="url">
             <value>jdbc:mysql://localhost:3306/security</value>
          </property>      
          
          <property name = "username">
             <value>root</value>
          </property>
                 
          <property name ="password">
             <value>password</value>         
          </property>   
    </bean> 
    -->

    <!-- JNDI DataSource for J2EE environments -->
    <!--
    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:comp/env/jdbc/petclinic"/>
    </bean>
    -->

        <!--SessionFactory defintion-->
        <!--The most standard configuration according to hibernate3-->
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="mappingResources">
    <value>com/itsz/hibernate/resources/account.hbm.xml</value>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.generate_statistics">true</prop>
    </props>
    </property>
    <property name="eventListeners">
    <map>
    <entry key="merge">
    <bean class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener"/>
    </entry>
    </map>
    </property>
    </bean>

    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    <!-- Transaction manager that delegates to JTA (for a transactional JNDI DataSource) -->
    <!--
    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
    -->

        <!-- ========================= BUSINESS OBJECT DEFINITIONS ========================= -->
        <!--central data access object: Hibernate implementation.
        -->
        <bean id ="accountDAO"
              class = "com.itsz.hibernate.dao.AccountDAO">
             <property name ="sessionFactory" ref="sessionFactory" />             
        </bean>

    <!--
    - Transactional proxy for the project's central data access object.
    -
    - Defines specific transaction attributes with "readOnly" ers,
    - which is an optimization that is particularly valuable with Hibernate
    - (to suppress unnecessary flush attempts for read-only operations).
    -
    - Note that in a real-life app with multiple transaction proxies,
    - you will probably want to use parent and child bean definitions
    - as described in the manual, to reduce duplication.
        -->
        
    <!--If those prepared well we can rely the transferway to realize it  -->
    <bean id = "accountDAOProxy"
          class = "org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
          <!-- such will refer to transactionManager -->
          <property name="transactionManager" ref="transactionManager"/>
          <property name="target" ref="accountDAO"/>                                     
          <!--such means that we would define the ways in userDAO transaction
            it will execute the arrange towards insert~ or get~-->      
          
        <property name="transactionAttributes">
             <props>
                <prop key="insert*">PROPAGATION_REQUIRED</prop>
                <prop key="get*">>PROPAGATION_REQUIRED,readOnly</prop>
             </props>
        </property>
    </bean>

    <!-- Hibernate 3.0's JMX statistics service -->
    <!-- Implements the StatisticsServiceMBean management interface -->
    <bean name="database:type=HibernateStatistics" class="org.hibernate.jmx.StatisticsService">
    <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
         <!-- ========================= JMX EXPORTER DEFINITION ========================= --> <!--
      - Exporter that exposes Hibernate 3.0's statistics service via JMX.
    - Autodetects the statistics service, which is a standard MBean,
    - using its bean name as JMX object name.
    -
    - By default, the standard MBeanServerFactory.findMBeanServer method will be used
    - to determine the MBeanServer. Unfortunately, this does not work on WebLogic <= 8.1:
    - you need to comment in the WebLogicMBeanServerFactoryBean definition on WebLogic,
    - specifying appropriate configuration values there.
        -->
    <bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter">
    <property name="autodetect" value="true"/>
    <!-- Comment the following in on WebLogic <= 8.1, which doesn't support -->
    <!-- the standard MBeanServerFactory.findMBeanServer lookup mechanism. -->
    <!--
    <property name="server">
    <bean class="org.springframework.jmx.support.WebLogicJndiMBeanServerFactoryBean"/>
    </property>
    -->
    </bean>

    </beans>