Lookup jndi资源WebSphere 8.5,Spring 3.1.3,Hibernate 4.1.10 EJB 3 [英] Lookup jndi resources WebSphere 8.5, Spring 3.1.3, Hibernate 4.1.10 EJB 3

查看:113
本文介绍了Lookup jndi资源WebSphere 8.5,Spring 3.1.3,Hibernate 4.1.10 EJB 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我需要查找jndi资源以进行数据库连接。



我有一个包含我的远程和无状态ejb的EJB项目的EAR: ABean.jar



阅读使用Spring和Hibernate与WebSphere Application Server 我在EAR项目的 application.xml 中定义了

 < module> 
< ejb> ABean.jar< / ejb>

< / module>

< resource-ref>
< res-ref-name> jdbc / b< / res-ref-name>
< res-type> javax.sql.DataSource< / res-type>
< res-auth>容器< / res-auth>
< res-sharing-scope>可共享< / res-sharing-scope>
< / resource-ref>

在我的春天的环境中:

 < jee:jndi-lookup 
id =aDataSource
jndi-name =jdbc / b
cache =true
预期型= javax.sql.DataSource中/>

< bean id =entityManagerFactoryclass =org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean>
< property name =persistenceXmlLocationvalue =META-INF / persistence.xml/>
< property name =dataSourceref =aDataSource/>
< property name =persistenceUnitNamevalue =APU/>
< property name =jpaProperties>
<道具>
< prop key =hibernate.dialect> org.hibernate.dialect.DB2390Dialect< / prop>
< prop key =hibernate.show_sql> true< / prop>
< / props>
< / property>
< property name =jpaDialect>
< bean class =org.springframework.orm.jpa.vendor.HibernateJpaDialect/>
< / property>
< / bean>

现在,如果我通过WebSphere控制台安装应用程序,它要求我将jndi资源分配给 jdbc / b (这是可以的),但是如果我尝试调用一个ejb,一个 NameNotFoundException 被抛出,因为 jdbc / b 未找到!



阅读更好的上一个链接我看到:


对于EJB JAR文件,应在需要访问数据源的每个EJB中声明相同的资源引用。


所以我试图将资源引用定义到我的 ejb-jar.xml中

 <企业豆> 
< session>
< ejb-name> TestServiceBean< / ejb-name>
< ejb-class> it.test.TestServiceBean< / ejb-class>
< session-type> Stateless< / session-type>
< transaction-type> Container< / transaction-type>
< resource-ref>
< res-ref-name> jdbc / b< / res-ref-name>
< res-type> javax.sql.DataSource< / res-type>
< / resource-ref>
< / session>
< / enterprise-beans>

我尝试再次安装(我也将jndi资源分配给$ code> jdbc / b] / ejb的调用成功运行,但是如果我有n ejb,那么需要将n次相同的jndi资源分配给jdbc / b的n ejb resource-ref? / p>

我的配置有什么问题?所有ejb都不能同 resource-ref ?你有完整的例子吗?

解决方案

根据EE 6规范,在 application.xml中声明的引用必须位于 java:app (或 java:global )命名空间中,而建议他们在 env 子上下文中,所以:

  ; RES-REF-名称>的java:应用/ env的/ JDBC / b将/ RES-REF-名称> 

这将允许资源对应用程序中的所有组件都可见。或者,您可以在ejb-jar.xml中的 java:module 上下文中或通过注释声明一个引用。


In my application I need to lookup jndi resources for database connection.

I have an EAR which contain my EJB project with remote and stateless ejb: ABean.jar

Reading Using Spring and Hibernate with WebSphere Application Server I defined in the application.xml of EAR project:

<module>
    <ejb>ABean.jar</ejb>

</module>

<resource-ref>
    <res-ref-name>jdbc/b</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

In my spring context:

<jee:jndi-lookup
    id="aDataSource" 
    jndi-name="jdbc/b" 
    cache="true" 
    expected-type="javax.sql.DataSource"/>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceXmlLocation" value="META-INF/persistence.xml"/>
    <property name="dataSource" ref="aDataSource" />
    <property name="persistenceUnitName" value="APU"/>
    <property name="jpaProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.DB2390Dialect</prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>
    <property name="jpaDialect">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
    </property> 
</bean>

Now, if I install application by WebSphere console, it ask to me to assign the jndi resource to jdbc/b (and it is ok), but if I try to call an ejb, a NameNotFoundException is throw because jdbc/b is not found!

Reading better the previous link i see:

For EJB JAR files, the same resource-ref should be declared in each EJB that needs to access the data source.

so I try to define resource references into my ejb-jar.xml

<enterprise-beans>
<session>
   <ejb-name>TestServiceBean</ejb-name>
   <ejb-class>it.test.TestServiceBean</ejb-class>
   <session-type>Stateless</session-type>
   <transaction-type>Container</transaction-type>
   <resource-ref>
        <res-ref-name>jdbc/b</res-ref-name>         
        <res-type>javax.sql.DataSource</res-type>   
   </resource-ref>
 </session>
 </enterprise-beans>

I try to install again (I also assign the jndi resource to jdbc/b) and the call to the ejb run successfully, but if I have n ejb, do I need to assign n-times the same jndi resource to the n ejb resource-ref for jdbc/b?

What is wrong with my configuration? Isn't it possible "point" to the same resource-ref from all ejb? Do you have a complete example?

解决方案

Per the EE 6 spec, references declared in application.xml must be in the java:app (or java:global) namespaces, and it is recommend that they be in the env subcontext, so:

<res-ref-name>java:app/env/jdbc/b</res-ref-name>

This will allow the resource to be visible to all components in the application. Alternatively, you can declare a reference in the java:module context in ejb-jar.xml or via annotation.

这篇关于Lookup jndi资源WebSphere 8.5,Spring 3.1.3,Hibernate 4.1.10 EJB 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆