当前位置: 代码迷 >> J2EE >> 请问一个关于hibernateTemplate的有关问题
  详细解决方案

请问一个关于hibernateTemplate的有关问题

热度:403   发布时间:2016-04-22 03:37:47.0
请教一个关于hibernateTemplate的问题
我在注入hibernateTemplate的时候总是发现它的值为null. 但是检查不出原因来。 下面是我的代码, 麻烦大家帮忙查一下

AdminUserDAOImpl.java
-------------------------------- 
package com.brolinuk.irms.DAO;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.sworduk.irms.admin.AdminUser;

public class AdminUserDAOImpl extends HibernateDaoSupport implements AdminUserDAO{
  public void create(AdminUser adminuser) throws DataAccessException {
  getHibernateTemplate().save(adminuser);
  }
}

applicationContext.xml
————————————————————
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- DataSource Definition -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/irms</value>
</property>
<property name="username">
<value>system</value>
</property>
<property name="password">
<value>system</value>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>adminUser.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLInnoDBDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="jdbcExceptionTranslator" class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
<property name="jdbcExceptionTranslator">
<ref bean="jdbcExceptionTranslator"/>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="adminUserDAO" class="com.brolinuk.irms.DAO.AdminUserDAOImpl">
<property name="hibernateTemplate">
<ref bean="hibernateTemplate"/>
</property>
</bean>
<bean id="adminService" class="com.brolinuk.irms.admin.AdminServiceImpl">
<property name="adminUserDAO">
<ref local="adminUserDAO"/>
</property>
</bean>
</beans>




------解决方案--------------------
  相关解决方案