6
回答
spring事物管理 报空指针异常
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

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

举报
李修恒
发帖于5年前 6回/868阅
顶部