开发者社区> 问答> 正文

spring事物管理 报空指针异常

<?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"> 
  
 <bean id="mdao" class="dao.ManagerDao"> 
  <property name="sessionFactory" ref="sessionFactory" /> 
 </bean> 
 
这是运行结果抱的异常

log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.ExceptionInInitializerError
 at org.springframework.context.support.AbstractRefreshableApplicationContext.createBeanFactory(AbstractRefreshableApplicationContext.java:194)
 at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:127)
 at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397)
 at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
 at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
 at com.Test.main(Test.java:23)
Caused by: java.lang.NullPointerException
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.<clinit>(DefaultListableBeanFactory.java:104)
 ... 7 more

 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> 
  <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/> 
  <property name="url" value="jdbc:oracle:thin:@127.0.0.1 :1521:mydb"/> 
  <property name="username" value="LIXIUHENG"/> 
  <property name="password" value="123456"/> 
 </bean> 
  
 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
  <property name="dataSource" ref="dataSource"/> 
  <property name="hibernateProperties"> 
   <props> 
    <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop> 
   </props> 
  </property> 
  <property name="mappingResources"> 
   <list> 
    <value>bean/Student.hbm.xml</value> 
    <value>bean/Person.hbm.xml</value> 
   </list> 
  </property> 
 </bean> 
  
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 
  <property name="dataSource" ref="dataSource"/> 
 </bean> 
  
 <bean id="transactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> 
  <property name="transactionManager" ref="transactionManager"/> 
  <property name="target" ref="mdao"/> 
  <property name="proxyTargetClass" value="true"/> 
  <property name="transactionAttributes"> 
   <props> 
    <prop key="query*">PROPAGATION_REQUIRED,timeout_5,readOnly</prop> 
    <prop key="in*">PROPAGATION_REQUIRED</prop> 
    <prop key="delete*">PROPAGATION_REQUIRED</prop> 
   </props> 
  </property> 
 </bean> 
  
</beans>

展开
收起
a123456678 2016-03-13 15:40:22 2428 0
1 条回答
写回答
取消 提交回答
  • 事物配置换成:

    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager"
        abstract="false" lazy-init="default" autowire="default">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    2019-07-17 19:02:40
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载

相关实验场景

更多