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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jee="http://www.springframework.org/schema/jee"
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.xsd">






<!-- 历史库数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>com.ibm.db2.jcc.DB2Driver</value>
</property>
<property name="url">
<value>jdbc:db2://182.180.48.194:50000/NGUHIS</value>
</property>
<property name="username">
<value>db2admin</value>
</property>
<property name="password">
<value>pccc_123</value>
</property>
</bean>


<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>SqlMapConfig.xml</value>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
          <property name="dataSource">
                 <ref local="dataSource" />
          </property>
    </bean>
   



<bean id="hisQueueItemHis" class="com.bocom.pccc.task.datatransfer.dao.THisqueueitemDAOImpl">
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
</bean>



......中间是一些DAO  bean

<bean id="transferState" class="com.bocom.pccc.task.datatransfer.dao.TApptransferstateDAOImpl">
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
</bean>

<bean id="generalApplyArchive" class="com.bocom.pccc.task.dataArchive.GeneralApplyArchive">
</bean>

<bean id="fqbApplyArchive" class="com.bocom.pccc.task.dataArchive.FQBApplyArchive">
</bean>

<bean id="commonApplyArchive"class="com.bocom.pccc.task.dataArchive.CommonApplyArchive">
</bean>

<bean id="generalProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
          <property name="transactionManager">
                  <ref bean="transactionManager" />
          </property>
          <property name="target">
                  <ref local="generalApplyArchive" />
          </property>
          <property name="transactionAttributes">
          <props>
                <prop key="generalApplyDelete">PROPAGATION_REQUIRED</prop>
                
          </props>
          </property>
     </bean>
     
     <bean id="fqbProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
          <property name="transactionManager">
                  <ref bean="transactionManager" />
          </property>
          <property name="target">
                  <ref local="fqbApplyArchive" />
          </property>
          <property name="transactionAttributes">
          <props>
                <prop key="fqbApplyDelete">PROPAGATION_REQUIRED</prop>
                
          </props>
          </property>
     </bean>
     
     <bean id="commonProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
          <property name="proxyTargetClass">
          <value>true</value>
          </property>
          <property name="transactionManager">
                  <ref bean="transactionManager" />
          </property>
          <property name="target">
                  <ref local="commonApplyArchive" />
          </property>
          <property name="transactionAttributes">
          <props>
                <prop key="commonApplyDelete">PROPAGATION_REQUIRED</prop>
                
          </props>
          </property>
     </bean>
     
    
</beans>
    CommonApplyArchive.java:   package com.bocom.pccc.task.dataArchive;import com.bocom.pccc.task.datatransfer.model.*;
import java.sql.SQLException;
import java.util.*;public class CommonApplyArchive extends BaseDAO{
/**
 * 删除共有文件以及共有文件下的申请件在历史库中的记录
 */
public void commonApplyDelete(Long insideAppNo,String barCodeNo)throws SQLException{
logQueueDelete( insideAppNo );
postilInfoDelete( insideAppNo );
supplyInfoDelete( insideAppNo );
supplyDataInfoDelete( insideAppNo );
supplyReasonInfoDelete( insideAppNo );
mistakeInfoDelete( insideAppNo );
appQueueFlagDelete( insideAppNo );
commonFileDelete( barCodeNo );
commonFileCheckDelete( barCodeNo );
imageFileInfoDelete( insideAppNo );
deleteGeneralApplyByBarCodeNo(barCodeNo);
hisQueueItemDelete( insideAppNo );
updateState( insideAppNo );
}

/**
 * 删除共有文件下的申请件在历史库中的记录
 */
protected void deleteGeneralApplyByBarCodeNo(String barCodeNo)throws SQLException{
THisqueueitem tHisqueueitem = null;
GeneralApplyArchive gaa = new GeneralApplyArchive();
THisqueueitemExample example = new THisqueueitemExample();
THisqueueitemExample.Criteria ct = example.createCriteria();
    ct.andBarcodenoEqualTo(barCodeNo);
    List list = hisQueueItemDao.selectByExample(example);
    for(int i=0;i<list.size();i++){
     tHisqueueitem = (THisqueueitem)list.get(i);
     gaa.generalApplyDelete(tHisqueueitem.getInsideappno());
    }
}
    
protected void commonFileDelete( String barCodeNo )
{
commonFileDao.deleteByPrimaryKey( barCodeNo );
}

protected void commonFileCheckDelete( String barCodeNo )
{
commonFileCheckDao.deleteByPrimaryKey( barCodeNo );
}

/**
 * 查询出符合归档条件的共有文件申请件
 */
protected  List queryCommonItemsByArchivetime(Date date){
TApptransferstateExample example = new TApptransferstateExample();
TApptransferstateExample.Criteria ct = example.createCriteria();
ct.andStateEqualTo("0");
//ct.andFilesubtypeEqualTo("B");
//ct.andTransferdateLessThan(date);
List list = transferStateDao.selectByExample(example);
return list;
}
}
    (dao是一个初始化spring上下文和DAO的类对象,因为篇幅太长就不贴出来了,此对象我实例化过的)
    现在我这样CommonApplyArchive ca = (CommonApplyArchive )dao.context.getBean("commonProxy");
              Date date = new Date();               
              ca.queryCommonItemsByArchivetime(date);(调用此方法就报如下的空指针异常):
        Exception in thread "main" java.lang.NullPointerException
at com.bocom.pccc.task.dataArchive.CommonApplyArchive.queryCommonItemsByArchivetime(CommonApplyArchive.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:615)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:299)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:690)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:139)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:628)
at com.bocom.pccc.task.dataArchive.CommonApplyArchive$$EnhancerByCGLIB$$16c1ce5f.queryCommonItemsByArchivetime(<generated>)
at com.bocom.pccc.task.dataArchive.DataArchiveTask.launchTask(DataArchiveTask.java:57)
at com.bocom.pccc.task.dataArchive.Test.main(Test.java:14)哪位高人帮我看是哪出问题了?

解决方案 »

  1.   

    可根据我的配置:
    <bean id="commonProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> 
              <property name="proxyTargetClass"> 
              <value>true </value> 
              </property> 
              <property name="transactionManager"> 
                      <ref bean="transactionManager" /> 
              </property> 
              <property name="target"> 
                      <ref local="commonApplyArchive" /> 
              </property> 
              <property name="transactionAttributes"> 
              <props> 
                    <prop key="commonApplyDelete">PROPAGATION_REQUIRED </prop> 
                    
              </props> 
              </property> 
        </bean> 
    应该是可以获得这个代理bean对象的啊
      

  2.   

    bean  commonApplyArchive是个service类,里面有很多dao层的操作,我就是想代理这个service类进行事务管理的
      

  3.   

    <bean id="commonApplyArchive"class="com.bocom.pccc.task.dataArchive.CommonApplyArchive" autowire="byType"
    </bean> 
      

  4.   

    CommonApplyArchive  是接口么?
      

  5.   

    at com.bocom.pccc.task.dataArchive.DataArchiveTask.launchTask(DataArchiveTask.java:57) 
      

  6.   

    不是,CommonApplyArchive  只是一个service类
    所以我在配置文件中申明了是类代理而不是接口代理
    <property name="proxyTargetClass"> 
              <value>true </value> 
              </property>