[jboss-user] [Microcontainer] - Re: Programmatically getting JNDI Context
alesj
do-not-reply at jboss.com
Mon Nov 3 03:22:36 EST 2008
"amit.bhayani at 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 at 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. :-)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4186317#4186317
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4186317
More information about the jboss-user
mailing list