使用JNDI将Bean插入JBoss [英] Plug Bean to JBoss with JNDI
问题描述
我想知道如何使用JNDI将对象(如果需要EJB)可以插入到JBoss(5.0)中?
我的Spring中有以下bean定义 applicationContext.xml :
< bean id =transactionManagerclass =org.springframework.orm .jpa.JpaTransactionManager>
< property name =entityManagerFactoryref =entityManagerFactory/>
< / bean>
< tx:注释驱动的transaction-manager =transactionManager/>
< context:annotation-config />
< bean id =myServiceFacadeclass =org.springframework.jndi.JndiObjectFactoryBean>
< property name =jndiNamevalue =MyServiceFacadeBean / remote/>
< property name =cachevalue =true/>
< property name =lookupOnStartupvalue =true/>
< property name =jndiEnvironment>
<道具>
< prop key =java.naming.factory.initial> org.jnp.interfaces.NamingContextFactory
< / prop>
< prop key =java.naming.provider.url> localhost:1099< / prop>
< prop key =java.naming.factory.url.pkgs> org.jboss.naming:org.jnp.interfaces
< / prop>
< / props>
< / property>
< property name =proxyInterfacevalue =my.company.service.facade.MyServiceFacade/>
< / bean>
当我尝试运行JBoss时,我得到:
导致:javax.naming.NameNotFoundException:MyServiceFacadeBean / remote
在org.jboss.ha.jndi.HAJNDI.lookup远程(HAJNDI.java:264)
在org.jboss.ha.jndi.HAJNDI.lookup(HAJNDI.java:205)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl .java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
在java.lang.reflect.Method.invoke(Method.java:597)
at $ org
$ / $ $ $ $ $ >
也许应该使用JBoss / JNDI注册对象的其他步骤?注意,我已经尝试将ejb特定的文件放到JBoss(jboss.xml,ejb-jar.xml)中,但这并不有用。
如何在DataSource中循环远程?但是我确信你不能从你的MyServiceFacadeBean获取它。
在applicationContext.xml中:
< property name =jndiNamevalue =remote/>
尽管放开,
Context ctx = new InitialContext();
DataSource ds =(DataSource)ctx.lookup(java:comp / env / remote);
DataSource ds =(DataSource)envCtx.lookup(remote);
或者你可以做一个中间步骤,所以你不必指定java:comp / env 对于您检索的每个资源:
上下文ctx = new InitialContext();
上下文envCtx =(Context)ctx.lookup(java:comp / remote);
DataSource ds =(DataSource)envCtx.lookup(remote);
希望有帮助。
I wonder how object (if it matter I need EJB) can be plugged to JBoss (5.0) with JNDI?
I have following bean definition in my Spring applicationContext.xml:
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<context:annotation-config/>
<bean id="myServiceFacade" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="MyServiceFacadeBean/remote"/>
<property name="cache" value="true"/>
<property name="lookupOnStartup" value="true"/>
<property name="jndiEnvironment">
<props>
<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory
</prop>
<prop key="java.naming.provider.url">localhost:1099</prop>
<prop key="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces
</prop>
</props>
</property>
<property name="proxyInterface" value="my.company.service.facade.MyServiceFacade"/>
</bean>
when I try to run JBoss I get:
Caused by: javax.naming.NameNotFoundException: MyServiceFacadeBean/remote
at org.jboss.ha.jndi.HAJNDI.lookupRemotely(HAJNDI.java:264)
at org.jboss.ha.jndi.HAJNDI.lookup(HAJNDI.java:205)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.ha.framework.interfaces.HARMIClient.invoke(HARMIClient.java:318)
at $Proxy165.lookup(Unknown Source)
Maybe some additional steps should be made for registering objects with JBoss/JNDI?
Note, I've tried already to put ejb specific files to JBoss (jboss.xml, ejb-jar.xml) but that doesn't help.
How do you loop-up remote in your DataSource? But I am sure you can't get it from your MyServiceFacadeBean.
in applicationContext.xml:
<property name="jndiName" value="remote"/>
While loooping up,
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:comp/env/remote");
DataSource ds = (DataSource)envCtx.lookup("remote");
or you could make an intermediate step so you don't have to specify "java:comp/env" for every resource you retrieve:
Context ctx = new InitialContext();
Context envCtx = (Context)ctx.lookup("java:comp/remote");
DataSource ds = (DataSource)envCtx.lookup("remote");
Hope it helps.
这篇关于使用JNDI将Bean插入JBoss的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!