Announcement Announcement Module
Collapse
No announcement yet.
How configure aop:pointcut, aop:advisor, tx:advice into JavaConfig... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How configure aop:pointcut, aop:advisor, tx:advice into JavaConfig...

    Hello Guys

    I have the follow two classes

    Code:
    @Configuration
    public class SpringFrameworkTransactionConfiguration {
    
    	private SessionFactory sessionFactory;
    	
    	@Autowired
    	public void setSessionFactory(SessionFactory sessionFactory) {
    		this.sessionFactory = sessionFactory;
    	}
    
    
    	@Bean
    	public PlatformTransactionManager transactionManager(){
    		
    		HibernateTransactionManager transactionManager = new HibernateTransactionManager();
    		
    		transactionManager.setSessionFactory(sessionFactory);
    		
    		return transactionManager;
    		
    	}
    }
    And

    Code:
    @Configuration
    @EnableTransactionManagement
    @ImportResource(value={"classpath:/com/manuel/jordan/springframework/beans/xml/spring-framework-transaction-service-repository-configuration.xml"})
    public class SpringFrameworkTransactionServiceRepositoryConfiguration {
    
    }
    According with the @EnableTransactionManagement API it says..

    In both of the scenarios above, @EnableTransactionManagement and <tx:annotation-driven/> are responsible for registering the necessary Spring components that power annotation-driven transaction management, such as the TransactionInterceptor and the proxy- or AspectJ-based advice that weave the interceptor into the call stack when JdbcFooRepository's @Transacational methods are invoked.
    Therefore @EnableTransactionManagement is the same than <tx:annotation-driven/>

    Now my file spring-framework-transaction-service-repository-configuration.xml has the follow

    Code:
    <aop:config>
    	
    	<aop:pointcut id="service"
    		            expression="execution(* com.manuel.jordan.service.impl.sinannotations.*ServiceImpl.*(..) )" />
    	<aop:pointcut id="repository"
    		            expression="execution(* com.manuel.jordan.repository.hibernate.sinannotations.*Repository.*(..) )" />
    			              
    	<aop:advisor pointcut-ref="service" advice-ref="txAdvice"/>
    	<aop:advisor pointcut-ref="repository" advice-ref="txAdvice"/>
    		              
    </aop:config>
    	
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
    	<tx:attributes>
    		<tx:method name="*"/>
    	</tx:attributes>	
    </tx:advice>
    BTW: <tx:annotation-driven/> is declared in other file together with the transactionManager defined on XML, both with the purpose to be used only with Spring for XML or Annotation approaches...Such file never is loaded or referenced with JavaConfig, it is isolated for this approach.


    And The Java classes are free of any annotations...like this

    Code:
    public class ArticuloServiceImpl implements ArticuloService{
    
    	private static final Logger logger = LoggerFactory.getLogger(ArticuloServiceImpl.class);
    	
    	private ArticuloRepository articuloRepository;
    	
    	public ArticuloServiceImpl(ArticuloRepository articuloRepository){
    		this.articuloRepository = articuloRepository;
    	}
    ....
    }
    The Bean is created with JavaConfig

    Code:
    @Configuration
    public class SpringFrameworkServiceConfiguration {
    
    	@Bean
    	public ArticuloService articuloService(ArticuloRepository articuloRepository){
    		ArticuloService articuloService = new ArticuloServiceImpl(articuloRepository);
    		return articuloService;
    	}
    ...
    }
    Therefore:
    How I can configure aop : point cut, aop:advisor, tx:advice into JavaConfig... to avoid in a 100% XML?

    I know I can mix XML with JavaConfig and annotations... but in the case I have the explicit situation to use Java in a 100% without XML and annotations...How I can do this?

    Thank You.
Working...
X