cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robby Pelssers" <robby.pelss...@ciber.com>
Subject RE: using Spring AOP in cocoon block
Date Tue, 06 Oct 2009 12:20:12 GMT
So I added following dependencies to my pom.xml:
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjrt</artifactId>
      <version>1.6.4</version>
    </dependency>
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjweaver</artifactId>
      <version>1.6.4</version>
    </dependency>

When I add following bean to the folder META-INF/cocoon/spring I run into the exception below:

Bean
---------------------------------------------------------------------------------------------------
<?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:p="http://www.springframework.org/schema/p"
  xmlns:aop="http://www.springframework.org/schema/aop"
  xmlns:util="http://www.springframework.org/schema/util"
  xmlns:pipeline="http://cocoon.apache.org/schema/pipeline"
  xsi:schemaLocation="
  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
  http://cocoon.apache.org/schema/pipeline http://cocoon.apache.org/schema/pipeline/cocoon-pipeline-1.0.xsd">
 
    <aop:aspectj-autoproxy/>

</beans>

Any ideas somebody??

Robby


Stacktrace:
---------------------------------------------------------------------------------------------------
2009-10-06 14:11:34.566::WARN:  Failed startup of context org.mortbay.jetty.plugin.Jetty6PluginWebAppContext@1ff8506{/,D:\workspaces\spider\spring\target\rcl\webapp}
java.lang.RuntimeException: Cannot invoke listener org.springframework.web.context.ContextLoaderListener@c71c00
	at org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingListener.invoke(ReloadingListener.java:190)
	at org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingListener.contextInitialized(ReloadingListener.java:213)
	at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:540)
	at org.mortbay.jetty.servlet.Context.startContext(Context.java:135)
	at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
	at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:510)
	at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
	at org.mortbay.jetty.plugin.Jetty6PluginWebAppContext.doStart(Jetty6PluginWebAppContext.java:110)
	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
	at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
	at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
	at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
	at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:117)
	at org.mortbay.jetty.Server.doStart(Server.java:222)
	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
	at org.mortbay.jetty.plugin.Jetty6PluginServer.start(Jetty6PluginServer.java:132)
	at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:357)
	at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:293)
	at org.mortbay.jetty.plugin.AbstractJettyRunMojo.execute(AbstractJettyRunMojo.java:203)
	at org.mortbay.jetty.plugin.Jetty6RunMojo.execute(Jetty6RunMojo.java:182)
	at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:451)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:558)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:512)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:482)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:291)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
	at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
	at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
	at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with
name 'org.apache.cocoon.core.container.spring.avalon.AvalonBeanPostProcessor': Cannot resolve
reference to bean 'org.apache.cocoon.core.container.spring.avalon.ConfigurationInfo' while
setting bean property 'configurationInfo'; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'org.apache.cocoon.core.container.spring.avalon.ConfigurationInfo':
Post-processing of the FactoryBean's object failed; nested exception is org.springframework.aop.framework.AopConfigException:
Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or
specify proxy interfaces.
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1172)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:940)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:437)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:383)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:353)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:888)
	at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:594)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:351)
	at org.apache.cocoon.tools.rcl.springreloader.SynchronizedConfigureableWebApplicationContext.refresh(SynchronizedConfigureableWebApplicationContext.java:254)
	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:261)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
	at org.apache.cocoon.tools.rcl.wrapper.servlet.ReloadingListener.invoke(ReloadingListener.java:157)
	... 39 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with
name 'org.apache.cocoon.core.container.spring.avalon.ConfigurationInfo': Post-processing of
the FactoryBean's object failed; nested exception is org.springframework.aop.framework.AopConfigException:
Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or
specify proxy interfaces.
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport$1.run(FactoryBeanRegistrySupport.java:140)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:114)
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:90)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1269)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:256)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
	... 58 more
Caused by: org.springframework.aop.framework.AopConfigException: Cannot proxy target class
because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.
	at org.springframework.aop.framework.DefaultAopProxyFactory.createAopProxy(DefaultAopProxyFactory.java:67)
	at org.springframework.aop.framework.ProxyCreatorSupport.createAopProxy(ProxyCreatorSupport.java:106)
	at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110)
	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:433)
	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:299)[INFO]
Started Jetty Server

	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:331)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1340)
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport$1.run(FactoryBeanRegistrySupport.java:137)
	... 65 more
2009-10-06 14:11:34.597::INFO:  Started SelectChannelConnector@0.0.0.0:8888



-----Original Message-----
From: Robby Pelssers [mailto:robby.pelssers@ciber.com] 
Sent: Tuesday, October 06, 2009 1:10 PM
To: users@cocoon.apache.org
Subject: RE: using Spring AOP in cocoon block

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


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


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


Mime
View raw message