This content has been marked as final.
Show 1 reply
-
1. Re: Programmatically getting JNDI Context
alesj Nov 3, 2008 3:22 AM (in response to amit.bhayani)"amit.bhayani@jboss.com" wrote:
I have seen JndiDecoratedTestCase and it registers the beans to JNDI, but JNDI name is predefined here. While in my app the JNDI name is calculated at runtime.
As you could see in JndiDecoratedTestCase, to push bean in JNDI, you had to enable AOP interceptor:<interceptor xmlns="urn:jboss:aop-beans:1.0" name="JndiAspect" class="org.jboss.aop.microcontainer.aspects.jndi.JndiIntroduction"> <property name="env"> <map class="java.util.Properties" keyClass="java.lang.String" valueClass="java.lang.String"> <entry><key>java.naming.factory.initial</key><value>org.jboss.test.microcontainer.support.jndi.MockInitialContextFactory</value></entry> </map> </property> </interceptor> <introduction xmlns="urn:jboss:aop-beans:1.0" class="@org.jboss.aop.microcontainer.aspects.jndi.JndiBinding"> <interfaces>org.jboss.kernel.spi.dependency.KernelControllerContextAware</interfaces> </introduction> <bind xmlns="urn:jboss:aop-beans:1.0" pointcut="execution(* $instanceof{org.jboss.kernel.spi.dependency.KernelControllerContextAware}->$implements{org.jboss.kernel.spi.dependency.KernelControllerContextAware}(..))"> <interceptor-ref name="JndiAspect"/> </bind>
Although JndiIntroduction is deprecated and suggest usage of JndiLifecycleCallback (a lot easier == less xml):<lifecycle-configure xmlns="urn:jboss:aop-beans:1.0" name="DependencyAdvice" class="org.jboss.aop.microcontainer.aspects.jndi.JndiLifecycleCallback" classes="@org.jboss.aop.microcontainer.aspects.jndi.JndiBinding"> <property name="env"> <map class="java.util.Properties" keyClass="java.lang.String" valueClass="java.lang.String"> <entry><key>java.naming.factory.initial</key><value>org.jboss.test.microcontainer.support.jndi.MockInitialContextFactory</value></entry> </map> </property> </lifecycle-configure>
"amit.bhayani@jboss.com" wrote:
I am wondering how can this be achieved?
Why the code above?
To make you see it's all about configuration. ;-)
You can easily implement / configure your own interceptor / lifecycle.
e.g. custom @AmitsJndiAnnotation + matching lifecycle.
Or customize the one's above, as you can mix-n-match AOP schema with MC's.
You can either change original JndiLifecycleCallback - making it more customizable - or write your own.
In any case, push the changes here, and I'll make sure they get applied.
So other users already have all that configuration power you wanted. :-)