spring事物管理 报空指针异常

李修恒 发布于 2012/08/14 16:21
阅读 922
收藏 0

<?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>

加载中
0
喜之郎
喜之郎
log4j的配置文件有错。去网上复制一个正确的放到src下。
0
李修恒

肯定不是log4j的错误,别的工程用的同一个log4j,就是ApplicationContext.xml里配置错误。可是就是不知道哪错了?

0
c
chenbing
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource"/>
 </bean>
0
c
chenbing
你那是声明jdbc
0
景愿
景愿

事物配置换成:

	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager"
		abstract="false" lazy-init="default" autowire="default">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>

返回顶部
顶部