Simon,

If you really want to use Spring Aspects on ActionBeans, Evgeny is correct - the ActionBeans need to be managed by Spring. This has come up on the mailing list before (previous response below). I was able to get around some of the gotchas that Evgeny just described, but overall: unless you're looking to use other Spring services via annotations in ActionBeans, in addition to applying the aspects, then you're probably better off going with Stripes Interceptors or direct aspect weaving.

Chris.

Begin forwarded message:
From: Chris Herron <[EMAIL PROTECTED]>
Date: May 15, 2008 11:20:34 AM EDT
To: Stripes Users List <stripes-users@lists.sourceforge.net>
Subject: Re: [Stripes-users] Idea regarding use of class.newInstance() and spring integration

John,

I've looked into doing something like this specifically for ActionBeans. In my case, I wanted to use various Spring annotations (security, transaction) on my ActionBean event handler methods. In a nutshell, I extended Stripe's NameBasedActionResolver to fetch ActionBean instances from Spring.

Some of the issues I encountered:

* For Spring-managed ActionBeans, you can't use JDK dynamic proxies, because DP's require an interface to hide behind. Instead, I used CGLib proxies. With CGLib proxies, the ActionBean needs to be registered with Stripes twice; Once under the original class name, and again under the CGLib descendant class name e.g.
- com.foo.ExampleActionBean and...
- com.foo.ExampleActionBean$$EnhancerByCGLIB$$515e0936

* Creating explicit Spring XML config for lots of objects is a real bitch - and if you're a Stripes fan you'll probably want to stay away from that. My approach dynamically created Spring-managed ActionBeans in the Spring context. This worked fine until I switched to using Spring's WebApplicationContext. The Spring WebApplicationContext doesn't allow you to programmatically define beans. Bah.

In the end I shelved this work because I was doing fine without those annotations at the ActionBean level. Below is my original implementation of a Spring ActionResolver. Hope this helps.

Chris.

/**
* Instantiates Stripes ActionBeans by programmaticially defining a Spring bean. * This is preferable to defining every Stripes ActionBean in the application * context XML config. The main reason for doing this is to leverage Spring * interceptors for things like security. Note that because action beans are not * usually accessed via interfaces, CGLib proxies must be used instead of JDK * dynamic proxies. To do this, must have the following config in your Spring
 * application context XML:
 * <aop:config proxy-target-class="true"/>.
* Beware that CGLib proxies have certain limitations (e.g. cannot proxy methods
 * marked as final).
 *
 * @author cherro
 */
public class SpringActionResolver extends NameBasedActionResolver {
/** Tracks the ActionBeans that have already been defined in Spring. */
    private Set<String> processedBeanNames = new HashSet<String>();

    /** [EMAIL PROTECTED] */
    @Override
    protected ActionBean makeNewActionBean(
            Class<? extends ActionBean> type,
            ActionBeanContext actionBeanContext)
            throws Exception {
        final String beanName = type.getName();
        if (!processedBeanNames.contains(beanName)) {
            GenericApplicationContext springContext =
                    SpringUtil.getInstance().getContext();
BeanDefinition beanDefinition = new RootBeanDefinition(type);
            beanDefinition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
springContext.registerBeanDefinition(beanName, beanDefinition);
            ActionBean proxied =
                    (ActionBean) SpringUtil.getInstance().getContext()
                            .getBean(beanName, type);

// The CGLib proxy has a different class name (because it is a // subtype of the proxied class). So, we need to register the new
            // class in order to configure its event mappings.
            super.addActionBean(proxied.getClass());
            processedBeanNames.add(beanName);
            return proxied;
        } else {
            return (ActionBean) SpringUtil.getInstance().getContext()
                    .getBean(beanName, type);
        }
    }
}


On Jul 30, 2008, at 3:17 AM, Evgeny Shepelyuk wrote:

        Hello !

So with runtime-weaving as i understand u mean CGLIB proxy creation
(unlike pure JDK based approach).
Using Spring AOP means that your ActionBeans should be managed by Spring
for aspects to be applied.
This can be achieved using Stripes extension availabe from
http://www.stripesframework.org/display/stripes/Extended+Stripes-Spring+Support . But using this approach with CGLIB proxy creation you will fall in some
kind of troubles.
Spring AOP subclasses target class to apply method interceptors for AOP.
Since Stripes actively uses annotations -> those annotations won't be
inherited by newly created proxy class.
So for example if your Action bean has @DefaultHandler annotation and you
want to apply some advice to it
it will not be accesible because proxy class wotn inherit annotation.

So plz give a chance to interceptors or get rid of Spring AOP (not Spring
!!!) and use for example AspectJ compiler or AspectJ load-time weaving
Or maybe some other framework :))

This is from my personal expirience with Spring/Stripes/AOP. So i will be
glad to give u more feedbacks :)


29.07.08 в 13:17 Simon Faust в своём письме писал(а):

Hi,

I use Spring AOP / runtime-weaving.

Cheers, Simon

--
Best Regards
Evgeny K. Shepelyuk


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to