Hi Erik,

I hope you don't mind, but I've copied my answer to this in StackOverflow
b/c I think you might get more extra traction there than you will in this
mailing list.

(
http://stackoverflow.com/questions/23511287/injecting-a-component-in-an-aspect-in-a-non-spring-environment
)


Without understanding the exact internals of what you are doing (or perhaps
rather why), what you can do is something like the following in your
aspect. (Not the cleanest option, but at least a starting point)

If BusinessRuleManager is a singleton, how do you instantiate it/retrieve
it from elsewhere in the non-Spring application? Or is it used only within
the aspect?

 after(PersistentObject persistentObject) :
persistentObjectPropertySetter(persistentObject)
        {

                if(businessRuleManager!=null)

                       businessRuleManager = BusinessRuleManager.getInstance();


                if(businessRuleManager!=null)
                {
                        businessRuleManager.execute(persistentObject,
thisJoinPoint.getSignature().getName());
                }
        }

And in your BusinessRuleManager:

class BusinessRuleManager{
   .......
   static private BusinessRuleManager instance;

   static public BusinessRuleManager getInstance(){
     if( instance == null )
         instance = new BusinessRuleManager();

     return instance;
   }

   .......}

This should allow you to use the mix of Spring injection as well as a
non-spring container.


Thanks,

Eric


On May 8, 2014 9:34 AM, "erik" <evandeve...@fugro.be> wrote:

> Hello Eric,
>
> The answers to your questions are as follows:
> (1) Are you trying to get access to a Java bean from within your Aspect?
> It's more a service than a java bean. We are having trouble debugging our
> aspects in eclipse, and decided to delegate the real advise implementation
> to a helper component (which is easy to debug) as soon as we can. In my
> example i'm trying to 'inject' the helper component in one of our aspects.
> It's easy to configure with spring, but not without it.
> (2) Can you not use a factory-style approach to access it?
> I suppose we can do that, but assumed we followed a 'best practice' (?) in
> spring with the
>         <bean id="businessRuleAspect"
> class="com.fugro.gwf.domain.rules.aspects.BusinessRuleAspect"
>                 factory-method="aspectOf">
>                 <property name="businessRuleManager"
> ref="businessRuleManager" />
>         </bean>
> If we introduce some extra code in the aspect for the
> factory-style-approach, spring won't be used on either side. I'm not
> against
> that, just looking for opinions ... A question that still remains for me,
> even with the factory-style approach is: how is the aspect itself
> instantiated when I'm not using the spring configuration mentioned above?
> (3) Is the bean a singleton?
> Yes it is. Because that happened to be the standard for a spring managed
> bean ...
>
>
>
> --
> View this message in context:
> http://aspectj.2085585.n4.nabble.com/Injecting-a-component-in-a-non-spring-environment-tp4651384p4651391.html
> Sent from the AspectJ - users mailing list archive at Nabble.com.
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@eclipse.org
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
_______________________________________________
aspectj-users mailing list
aspectj-users@eclipse.org
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to