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; } */ }


Reply With Quote