Announcement Announcement Module
Collapse
No announcement yet.
Losing IoC on Declarative transaction (AOP transaction interceptor). Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Losing IoC on Declarative transaction (AOP transaction interceptor).

    Hi all, I am trying to implement a "Declarative transaction demarcation" based on AOP transaction interceptor,
    I have followed the Spring doc, but not success until now.
    Spring is not doing IoC, I think is due to my spring config is wrong.
    Any help would be appreciated.
    My code:

    Code:
    // Spring config:
    
    <?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:context="http://www.springframework.org/schema/context"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:p="http://www.springframework.org/schema/p"
    	xmlns:jee="http://www.springframework.org/schema/jee"
    	xmlns:aop="http://www.springframework.org/schema/aop"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans
    	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    	http://www.springframework.org/schema/jee 
    	http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
    	http://www.springframework.org/schema/context 
    	http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    	http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
    	
    	
    	<jee:jndi-lookup id="rauOracleDataSource" 
        				 jndi-name="java:comp/env/jdbc/DataSourceRaudo"
        				 proxy-interface="javax.sql.DataSource"/>
        
        <bean id="dataSourceBean" class="es.fega.comun.autenticacion.DataSourceImpl">
          <property name="dataSource" ref="rauOracleDataSource"/>
        </bean> 
        
        
        <bean id="transactionManager" 
        	class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory"/>
        </bean>
        
        <bean id="sessionFactory"  
            class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
            <property name="dataSource">  
                <ref bean="rauOracleDataSource" />  
            </property>  
            <property name="hibernateProperties">  
                <props>  
    				<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
                    <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
                </props>  
            </property>
            <property name="mappingResources">  
                <list>  
                	<value>/es/fega/aplicacion/modelo/Documento.hbm.xml</value>
               </list>  
            </property>
        </bean> 
        
    
    
       <aop:config>
    		<aop:pointcut id="gestionDocumentosBOOperation" expression="execution(* es.fega.aplicacion.bo.impl.GestionDocumentosBOImpl.*(..))"/>
    		<aop:advisor advice-ref="txAdvice" pointcut-ref="gestionDocumentosBOOperation"/>
    	</aop:config>
    	
    	<tx:advice id="txAdvice" transaction-manager="transactionManager">
    		<tx:attributes>
    			<tx:method name="*" propagation="REQUIRED"/>
    		</tx:attributes>
    	</tx:advice>
    	
    	
    	<bean id="documentoDAO" class="es.fega.aplicacion.dao.impl.DocumentoDAOImpl">  
            <property name="sessionFactory" ref="sessionFactory" />
        </bean>
        
        <bean id="gestionDocumentosBO" class="es.fega.aplicacion.bo.impl.GestionDocumentosBOImpl">
    		<property name="documentoDAO">
    			<ref bean="documentoDAO"></ref>
    		</property>
    	</bean>
        
        
    </beans>
    
    
    // Action calls Service : servicioDocumento
    
    public class GestionDocumentosAction extends BaseAction implements ModelDriven<Object> {
    
    	private String mensajeOperacion;
    	private GestionDocumentosBOImpl servicioDocumento;
    	
    	
    	public String altaDocumento() {
    		try{
    			//servicioDocumento = new GestionDocumentosBOImpl();
    			this.mensajeOperacion = servicioDocumento.insercionPrueba();
    			System.out.println("insertaEmpleado");
    			
    		}catch(Exception e){
    			e.printStackTrace();
    		}
    		return "SUCCESS";
    	}
    	
    	public GestionDocumentosBOImpl getServicioDocumento() {
    		return servicioDocumento;
    	}
    
    	public void setServicioDocumento(GestionDocumentosBOImpl servicioDocumento) {
    		this.servicioDocumento = servicioDocumento;
    	}
    
    	public String getMensajeOperacion() {
    		return mensajeOperacion;
    	}
    	public void setMensajeOperacion(String mensajeOperacion) {
    		this.mensajeOperacion = mensajeOperacion;
    	}
    
    	public void setServletRequest(HttpServletRequest arg0) {
    		// TODO Auto-generated method stub
    		
    	}
    
    	@Override
    	public String executeOK() throws Exception {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    	public Object getModel() {
    		// TODO Auto-generated method stub
    		return null;
    	}
    }
    
    
    // Service
    
    public class GestionDocumentosBOImpl implements IGestionDocumentosBO {
    
    	private DocumentoDAOImpl documentoDAO;
    	
    	public void setDocumentoDAO(DocumentoDAOImpl documentoDAO) {
    		this.documentoDAO = documentoDAO;
    	}
    	public String getPrueba() throws Exception {
    		// TODO Auto-generated method stub
    		return null;
    	}
    	public String insercionPrueba() {
    			// Inserta
    			documentoDAO.insercionPrueba2();
    			documentoDAO.insercionPrueba();			
    			return null;
    	}
    	public String edicionPrueba() throws Exception {
    		// TODO Auto-generated method stub
    		return null;
    	}
    }
    
    // DAO
    
    public class DocumentoDAOImpl{
    	
    
    	//private DataSourceImpl dataSource;
    	private SessionFactory sesionFactory;
    	
        public void setSessionFactory(SessionFactory sessionFactory){
        	this.sesionFactory = sessionFactory;
        }
    	
    	public void insercionPrueba2(){
    		Session sesion = null;
    		
    		sesion = sesionFactory.getCurrentSession();
    		
            es.fega.aplicacion.modelo.PruebasPlantilla pruebaPlantilla = new es.fega.aplicacion.modelo.PruebasPlantilla();
            pruebaPlantilla.setP1(String.valueOf(java.lang.Math.random()));
            pruebaPlantilla.setP2(String.valueOf(java.lang.Math.random()));
            pruebaPlantilla.setP3(String.valueOf(java.lang.Math.random()));        
            sesion.save(pruebaPlantilla);
    	}
    	
    	public void insercionPrueba(){
    		Session sesion = null;
    		
    		sesion = sesionFactory.getCurrentSession();
    		
    		es.fega.aplicacion.modelo.PruebasPlantilla pruebaPlantilla = new es.fega.aplicacion.modelo.PruebasPlantilla();
            pruebaPlantilla.setP1(String.valueOf(java.lang.Math.random()));//String.valueOf(java.lang.Math.random()));
            pruebaPlantilla.setP2(String.valueOf(java.lang.Math.random()));
            pruebaPlantilla.setP3(String.valueOf(java.lang.Math.random()));
            sesion.save(pruebaPlantilla);
    	}
    
    	public void postInsercionPrueba() throws Exception {
    		throw new Exception("Prueba 2");
    	}
    
    /*
    	public DataSourceImpl getDataSource() {
    		return dataSource;
    	}
    
    	public void setDataSource(DataSourceImpl dataSource) {
    		this.dataSource = dataSource;
    	}
    	*/
    
    }

  • #2
    With a Oracle 10g DB pool and the thrown error is the following:

    Code:
    GRAVE: java.lang.NullPointerException
    	at es.fega.aplicacion.action.GestionDocumentosAction.altaDocumento(GestionDocumentosAction.java:19)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:601)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255)
    	at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
    	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
    	at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
    	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
    	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
    	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
    	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
    	at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:510)
    	at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:434)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    	at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    	at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
    	at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
    	at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
    	at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
    	at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
    	at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
    	at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
    	at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    	at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    	at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    	at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    	at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    	at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    	at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    	at java.lang.Thread.run(Thread.java:722)
    Last edited by estejorge; Dec 23rd, 2011, 04:55 AM.

    Comment


    • #3
      The config isn't wrong, your code is wrong. You should be programming to interfaces NOT concrete implementations. Spring uses a proxy based approach to AOP and by default it creates interface based proxies, in other words it creates an object that pretends to be a DocumentDAO and wraps that around your actual class. So it is a DocumentDAO NOT a DocumentDAOImpl.

      Also you are using WebWork make sure that your web work integration is working and setup correctly!

      Comment


      • #4
        Thanks Marten, as you can see, Im beginner but your help has been very helpful.

        Many thanks

        Comment

        Working...
        X