>>I haven't run into this because I tend to isolate any logic that needs
to be transactional in a single call in the service layer. However, I
can't think of a reason why it couldn't be made to work.
---------
Normally I don't use transaction interceptor on resource/action too, but how 
about security? Sooner or later we will have to intercept resource/action for 
other purpose.

>>Can you be more explicit about "just can not work"? How are you
trying to get it to work? What's the evidence that it is not working?
--------
First, my transaction does not rollback by the spring transaction interceptor, 
then I tried to connect to tomcat in debug mode, and found that the BeanFinder 
is not intercepted by spring cglib.


>>If the way you are loading resource configuration results in a plain
BeanFactory, then sure. But if your resources and the router are
defined and loaded as part of your Application Context, then
beanFactory will be the actual application context.
---------
Because I am not providing interfaces to some of my services, so spring uses 
cglib and which stops me tracing in debug mode. So I replaced SpringBeanFinder 
and print out the actual class passed in.

    public void setBeanFactory(BeanFactory beanFactory) {
        System.out.println("-------------------"+beanFactory.getClass());
        this.beanFactory = beanFactory;
    }

Unfortunately the output shows it's a beanFactory instead of a AppContext:
15:42:55 DEBUG http-8080-1 
org.springframework.beans.factory.support.DefaultListableBeanFactory - Eagerly 
caching bean '
rootRouter' to allow for resolving potential circular references
15:42:55 DEBUG http-8080-1 
org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished 
creating inst
ance of bean 'rootRouter'
-------------------class 
org.springframework.beans.factory.support.DefaultListableBeanFactory
-------------------class 
org.springframework.beans.factory.support.DefaultListableBeanFactory


If you look at SpringBeanRouter in the method postProcessBeanFactory:
    public void postProcessBeanFactory(ConfigurableListableBeanFactory factory)
            throws BeansException {
        String[] names = isFindInAncestors() ? BeanFactoryUtils
                .beanNamesForTypeIncludingAncestors(factory, Resource.class,
                        true, true) : factory.getBeanNamesForType(
                Resource.class, true, true);

        for (final String name : names) {
            final String uri = resolveUri(name, factory);
            if (uri != null) {
                attach(uri, createFinder(factory, name));
            }
        }
    }

This is where the beanFactory passed in, The passed in parameter is probably a 
DefaultListableBeanFactory instance.

I think Spring never passes in a WebAppContext to BeanFactoryPostProcessor 
(SpringBeanRouter ), so if only you use the current SpringBeanRouter you will 
never be able to get your Resource intercepted by AOP.

Can we just define SpringBeanFinder in appcontext.xml and get bean finder from 
bean router via WebApplicationContext cached in thread local instead of using a 
BeanFactoryPostProcessor to get a beanFactory to do the bean search?

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1013404

Reply via email to