当前位置: 代码迷 >> Java Web开发 >> HibernateSessionFactory.getSession()空指针错误
  详细解决方案

HibernateSessionFactory.getSession()空指针错误

热度:660   发布时间:2016-04-17 01:07:31.0
HibernateSessionFactory.getSession()空指针异常
DAO层中
Session session = HibernateSessionFactory.getSession();一直都是空指针,不知道问题出现在哪儿,貌似,HibernateSessionFactory里面并没有出现问题,应该是我的水平配置文件有问题,文件如下,麻烦,高手帮我查看一下空指针,为什么,会出现。

<?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: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-2.0.xsd
  http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
  <property name="url" value="jdbc:mysql://127.0.0.1:3306/expense"></property>
  <property name="username" value="root"></property>
  <property name="password" value="888888"></property>
  <property name="maxActive" value="100"></property>
  <property name="maxIdle" value="30"></property>
  <property name="maxWait" value="500"></property>
  <!-- please use AutoCode register edition ,We use XML mode configer the transaction ,the Function will Strong than Now ,thank you !-->
  <property name="defaultAutoCommit" value="true"></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.MySQLDialect</prop>
  <prop key="hibernate.show_sql">true</prop>
  </props>
  </property>

  <property name="mappingResources">
  <list>
  <value>ac/ssh/bean/Expense.hbm.xml</value>
  </list>
  </property>
</bean>

   
   
  <!-- 配置事务管理器 -->  
  <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  <property name="sessionFactory">  
  <ref local="sessionFactory"/>  
  </property>  
  </bean>  
   
  <!-- 配置事务特性 -->  
  <tx:advice id="txAdvice" transaction-manager="transactionManager">  
  <tx:attributes>  
  <tx:method name="*" propagation="REQUIRED"/>  
  <!--  
  <tx:method name="add*" propagation="REQUIRED"/>  
  <tx:method name="del*" propagation="REQUIRED"/>  
  相关解决方案