Robby Pelssers wrote:
Can someone tell me what is needed to get AOP working in a cocoon block?
· Dependencies
· Block configuration
· …?
Kind regards,
Robby
Hi!
so long i just worked with transactions as aop in cocoon. But i found
the documentation of spring really complete, it worked out of the box
for me.
http://static.springsource.org/spring/docs/2.0.x/reference/aop.html
May be a good point to start with aop. Check which version pf spring you
shall use and pick the doc after that. Newer in spring means most nicer
;-). Dependencies i used (i hope i did not overlook one):
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>2.5.1</version>
</dependency>
And in the block configuration (what is a own spring configuration file
for me, and i shotened it a bit, but i guess you can get the clue):
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!--
the transactional advice (what 'happens'; see the <aop:advisor/>
bean )
-->
<tx:advice id="applicationTxAdvice"
transaction-manager="applicationTransactionManager">
<!-- the transactional semantics... -->
<tx:attributes>
<!-- all methods starting with 'get' are read-only -->
<!--
Technically correct, but hibernate does not like it f you try to
create sqlQuery without transaction
-->
<tx:method name="get*" read-only="true" />
<!-- other methods use the default transaction settings (see below) -->
<tx:method name="*" rollback-for="Throwable"/>
</tx:attributes>
</tx:advice>
<!--
ensure that the above transactional advice runs for any execution of
an operation defined by the Service interfaces
-->
<aop:config>
<aop:pointcut id="applicationServiceOperation"
expression="execution(*
no.uninett.fas.application.service.*Service.*(..))" />
<aop:advisor advice-ref="applicationTxAdvice"
pointcut-ref="applicationServiceOperation" />
</aop:config>
<aop:config>
<aop:pointcut id="applicationHelperOperation"
expression="execution(*
no.uninett.fas.application.ApplicationHelper.*(..))" />
<aop:advisor advice-ref="applicationTxAdvice"
pointcut-ref="applicationHelperOperation" />
</aop:config>
<bean id="applicationSessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="hibernateDataSource"/>
<property name="mappingResources">
<list>
<value>YOURMAPPINGFILE1</value>
<value>YOURMAPPINGFILE2</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
</bean>
<bean id="applicationTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
lazy-init="true">
<property name="sessionFactory">
<ref bean="applicationSessionFactory" />
</property>
</bean>
<bean id="applicationDao"
class="no.uninett.fas.application.service.dao.ApplicationDAOHibernate"
scope="prototype">
<constructor-arg ref="applicationSessionFactory"/>
</bean>
<bean id="applicationConnectedDao"
class="no.uninett.fas.application.service.dao.ApplicationConnectedDAOHibernate"
scope="prototype">
<constructor-arg ref="applicationSessionFactory"/>
</bean>
<bean id="treeEntryDao"
class="no.uninett.fas.application.service.dao.TreeEntryDAOHibernate"
scope="prototype">
<constructor-arg ref="applicationSessionFactory"/>
</bean>
<bean id="applicationService"
class="no.uninett.fas.application.service.ApplicationServiceImpl"
scope="prototype">
<constructor-arg>
<ref bean="applicationDao" />
</constructor-arg>
</bean>
<bean id="applicationConnectedService"
class="no.uninett.fas.application.service.ApplicationConnectedServiceImpl"
scope="prototype">
<constructor-arg>
<ref bean="applicationConnectedDao" />
</constructor-arg>
</bean>
<bean id="treeEntryService"
class="no.uninett.fas.application.service.TreeEntryServiceImpl"
scope="prototype">
<constructor-arg>
<ref bean="treeEntryDao" />
</constructor-arg>
</bean>
<bean id="applicationHelper"
class="no.uninett.fas.application.ApplicationHelper"
scope="prototype">
<constructor-arg index="0">
<ref bean="applicationService" />
</constructor-arg>
<constructor-arg index="1">
<ref bean="applicationConnectedService" />
</constructor-arg>
<constructor-arg index="2">
<ref bean="treeEntryService" />
</constructor-arg>
</bean>
Hope that helps
Søren
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]