Hi Soren,

When installing a new Cocoon block I see that some Spring dependencies come 
out-of-the-box:

List of artifacts without a source archive:
  ...
  o org.springframework:spring-core:2.5.1
  o org.springframework:spring-context:2.5.1
  o aopalliance:aopalliance:1.0
  o org.springframework:spring-beans:2.5.1
  o org.springframework:spring-aop:2.5.1
  o org.springframework:spring-web:2.5.1
  ...

So this makes me wonder what else is needed in my cocoon-block pom.xml to get 
started.  I do want to use annotations like @Aspect, @Before and @Pointcut 
instead of declaring my aspects in an xml application context and just do

<aop:aspect-autoproxy>
  <aop:include name="someBean"/>
</ aop:aspect-autoproxy>

<bean id="someBean" class="com.xxx.SomeBean"/>

I'll try to get something simple working and when I do I'll write some 
documentation.

Cheers,
Robby Pelssers


-----Original Message-----
From: Søren Krum [mailto:soren.k...@uninett.no] 
Sent: Monday, October 05, 2009 8:28 AM
To: users@cocoon.apache.org
Subject: Re: using Spring AOP in cocoon block

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: users-unsubscr...@cocoon.apache.org
For additional commands, e-mail: users-h...@cocoon.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
For additional commands, e-mail: users-h...@cocoon.apache.org

Reply via email to