should dependencies be autowired from parent factory?

34 views
Skip to first unread message

Chris Blackwell

unread,
May 3, 2013, 4:17:28 PM5/3/13
to coldspring-users
I have a framework one app that has a parent beanfactory and one for each subsystem.
I was toying with the idea of using aop with annotations to do action based authorization on the controller methods.

So in my beanfactory for the  "home" subsystem i have

<bean id="AuthInterceptor" class="model.security.aop.AuthorizationInterceptor" /> 
<aop:config>
<aop:aspect ref="AuthInterceptor">
<aop:around method="authorize" pointcut="@annotation(authorize)" /> 
</aop:aspect>
</aop:config>
<bean id="TestController" class="modules.home.controllers.test" />

The problem is AuthInterceptor relies on some beans in the parent factory, like the SecurityService and these don't get wired in.

Is this a bug, or just tha way it is ?

Chris

Mark Mandel

unread,
May 5, 2013, 4:24:32 PM5/5/13
to coldspri...@googlegroups.com


--
You received this message because you are subscribed to the Google Groups "ColdSpring-Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldspring-use...@googlegroups.com.
To post to this group, send email to coldspri...@googlegroups.com.
Visit this group at http://groups.google.com/group/coldspring-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
E: mark....@gmail.com
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

2 Devs from Down Under Podcast

Chris Blackwell

unread,
May 14, 2013, 7:36:55 AM5/14/13
to coldspring-users
Hi Mark,

Well, that's what i thought.. but its not what i see

My CustomerController  bean is marked a BeanFactoryAware, and the Home beanfactory is correctly injected into it, so i know its getting loaded from the beanfactory and not by fw/1 manually instantiating it.  I've also double checked this by setting a property on it via the bean def.  

But if i execute this in my controller

dump(var=variables.beanFactory.containsbean("CustomerService"), label="contains bean CustomerService?");
dump(var=variables.beanFactory.hasParentBeanFactory(), label="has parent bean factory?");
dump(var=variables.beanFactory.getParentBeanFactory().containsbean("CustomerService"), label="parent contains bean CustomerService?");
abort;

I get 

contains bean CustomerService?
boolean false
has parent bean factory?
booleantrue
parent contains bean CustomerService?
boolean true

The problem is that when the child bean factory is created there is no parent set, so the BeanDefinistionRegistry is init'd with no reference to the parent.  This means that you can never get inside this if block.

A work around seems to be to call refresh() after setParentBeanFactory(), but its not obvious that you need to do that, so maybe this should be done for you inside setParentBeanFactory() ?

Chris

Mark Mandel

unread,
May 14, 2013, 8:40:51 PM5/14/13
to coldspri...@googlegroups.com
Ah.

I take it you are passing in the config locations through the init constructor?

You should really be using the advanced instantiation approach to set the parent before the .refresh() call.


Let me know if that works.

Mark

Chris Blackwell

unread,
May 20, 2013, 12:48:58 PM5/20/13
to coldspring-users

Yep, that fixes the problem.

Is this behaviour documented? If not, I think a note in the setParentBeanFactory docs and method hint would be a help.

I'll throw something together and submit it one way or t'other

Chris

Mark Mandel

unread,
May 20, 2013, 7:13:29 PM5/20/13
to coldspri...@googlegroups.com
Yeah - it probably should be added to the advanced configuration section:

Mark
Reply all
Reply to author
Forward
0 new messages