【问题标题】:How to tell Seam to inject a local EJB interface (SLSB) and not the remote EJB interface (SLSB)?如何告诉 Seam 注入本地 EJB 接口 (SLSB) 而不是远程 EJB 接口 (SLSB)?
【发布时间】:2011-02-12 20:07:23
【问题描述】:

我正在使用带有 JBoss AS 的 Seam。 在我的应用程序中,我有一个 SLSB,它也使用 @Name 注释声明为接缝组件。我正在尝试使用 @In 注释在另一个接缝组件中注入和使用这个 SLSB。

我的问题是,有时Seam会注入本地接口(然后代码运行良好),有时seam会注入远程接口(然后执行代码时出错)。我已经尝试做这个链接上指定的所有事情:http://docs.jboss.org/seam/2.2.0.GA/reference/en-US/html/configuration.html#config.integration.ejb.container

SeamInterceptor 已配置,
我在 components.xml 文件中指定了 jndi 模式( ),
我还尝试对每个 SLSB 使用 @JndiName("earName/ejbName/local") 注释,
我已尝试在 seam.properties 文件中设置此属性( org.jboss.seam.core.init.jndiPattern=earName/#{ejbName}/local )。
我也尝试将下面的文本放在 web.xml 文件中

<context-param>
    <param-name>org.jboss.seam.core.init.jndiPattern</param-name>
    <param-value>earName/#{ejbName}/local</param-value>
</context-param>  

即使做了上述所有事情,seam 有时仍然会注入远程接口。我在这里错过了什么吗?谁能告诉我如何解决这个问题并告诉 seam 总是注入本地接口?

我的 components.xml 文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<components xmlns="http://jboss.com/products/seam/components"
        xmlns:core="http://jboss.com/products/seam/core"
        xmlns:persistence="http://jboss.com/products/seam/persistence"
        xmlns:drools="http://jboss.com/products/seam/drools"
        xmlns:bpm="http://jboss.com/products/seam/bpm"
        xmlns:security="http://jboss.com/products/seam/security"
        xmlns:mail="http://jboss.com/products/seam/mail"
        xmlns:web="http://jboss.com/products/seam/web"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation=
            "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
             http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd
             http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd
             http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
             http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
             http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
             http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.1.xsd
             http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">
  <core:init debug="true" jndi-pattern="myEarName/#{ejbName}/local"/>
  <core:manager concurrent-request-timeout="500"
             conversation-timeout="120000"
             conversation-id-parameter="cid"
             parent-conversation-id-parameter="pid"/>
  <web:hot-deploy-filter url-pattern="*.seam"/>
  <persistence:managed-persistence-context name="entityManager" auto-create="true"
                  persistence-unit-jndi-name="@puJndiName@"/>
  <drools:rule-base name="securityRules">
    <drools:rule-files>
      <value>/security.drl</value>
    </drools:rule-files>
  </drools:rule-base>
  <security:rule-based-permission-resolver security-rules="#{securityRules}"/>
  <security:identity authenticate-method="#{authenticator.authenticate}" remember-me="true"/>
  <event type="org.jboss.seam.security.notLoggedIn">
     <action execute="#{redirect.captureCurrentView}"/>
  </event>
  <event type="org.jboss.seam.security.loginSuccessful">
     <action execute="#{redirect.returnToCapturedView}"/>
  </event>
  <component name="org.jboss.seam.core.init">
     <property name="jndiPattern">myEarName/#{ejbName}/local</property>
  </component>
</components>

我的 EJB 组件看起来像:

@Stateless @Name("myEJBComponent") @AutoCreate public class MyEJBComponentImpl implements MyEJBComponentRemote, MyEJBComponentLocal { public void doSomething() { } }

【问题讨论】:

  • 我检查了 jboss 日志,我在日志文件中观察到这一行:DEBUG [org.jboss.seam.Component] (main) org.jboss.seam.core.init.jndiPattern=myEarName/ #{ejbName}/local,jndiPattern 设置正确。
  • V 看来是对的!请尝试以下操作:移除远程接口,然后查看您的应用是否运行正常。如果没有,请显示您的 stackTrace。如果可能,不要使用 AutoCreate 注释。
  • @Arthur Ronald F D Garcia :好的,我删除了 AutoCreate 注释并将其替换为 @In(create=true)。我删除了所有远程接口,并运行了 6 次应用程序(因为即使使用远程接口,应用程序有时也可以正常工作),它运行了 6 次。我认为移除远程接口的接缝不会混淆,使用哪个接口,本地或远程。

标签: java ejb-3.0 seam jndi code-injection


【解决方案1】:

我猜是下面那个

 public interface MyStateless {

     void doSomething();         

 }

 /**
   * Be aware you CAN NOT USE @Local and @Remote at the same time
   */

 @Local
 public interface MyStatelessLocal extends MyStateless {}

 @Remote
 public interface MyStatelessRemote extends MyStateless {}

你的无状态应该看起来像

 /**
   * Global JNDI address will be earName/MyStatelessImpl/local and earName/MyStatelessImpl/remote
   */
 @Stateless
 @Name("myStateless")
 public class MyStatelessImpl implements MyStatelessLocal, MyStatelessRemote {

     public void doSomething() {

     }

 }

在你的 Seam 组件中

 @Name("otherSeamComponent")
 public class OtherSeamComponent {

     /**
       * Seam will lookup a Seam Component by field name - myStateless
       *
       * Notice i am using the local interface
       */
     private @In MyStatelessLocal myStateless;

 }

【讨论】:

  • 亚瑟,谢谢你的详细回复,但我正在做你提到的同样的事情,我仍然面临这个问题。
  • @Harshad V 所以我需要您展示您的应用程序的外观:/WEB-INF/components.xml,您的 EJB 组件,请参阅 stackoverflow.com/questions/2453746/… 您的应用程序应该如何好像。您使用哪个应用服务器?
  • 我正在使用 JBoss 5.1.0.GA 应用服务器。我检查了您提供的链接,我的应用程序看起来像链接上指定的那个,除了 myapp-ejb.jar 文件夹中没有 lib 文件夹并且 myapp-war.war 文件夹中的 lib 文件夹位于 WEB-INF 文件夹中,即 myapp-war.war\WEB-INF\lib 。我在上面编辑了我的问题并添加了我的 components.xml 和 EJB 组件。
【解决方案2】:

@Arthur Ronald F D Garcia:我的错,我忽略了你在上面发布的答案的一小部分。

在我的应用程序中,我有 MyStatelessLocal 和 MyStatelessRemote 接口,但没有 MyStateless 父接口。我在本地和远程接口中都添加了抽象方法,它们不是空的。

当我创建了一个 MyStateless 父接口,将抽象方法从本地和远程接口移动到父接口(使本地和远程接口为空)时,错误得到解决,现在我的应用程序工作正常!

非常感谢您的帮助!

--Harshad Vyawahare.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-12
    • 2017-03-13
    • 1970-01-01
    • 1970-01-01
    • 2011-04-17
    • 2020-09-03
    • 2012-09-13
    相关资源
    最近更新 更多