java - 如何告诉 Seam 注入(inject)本地 EJB 接口(interface)(SLSB)而不是远程 EJB 接口(interface)(SLSB)?

标签 java ejb-3.0 seam jndi code-injection

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

我的问题是,有时 Seam 注入(inject)本地接口(interface)(然后代码运行正常),有时 seam 注入(inject)远程接口(interface)(然后代码执行出错)。我已尝试执行此链接上指定的所有操作:http://docs.jboss.org/seam/2.2.0.GA/reference/en-US/html/configuration.html#config.integration.ejb.container

SeamInterceptor配置好了,
我在 components.xml 文件中指定了 jndi 模式( < core:init debug="true"jndi-pattern="earName/#{ejbName}/local"/> ),
我还尝试为每个 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>  

即使做了上面提到的所有事情,接缝有时仍然会注入(inject)远程接口(interface)。我在这里错过了什么吗?谁能告诉我如何解决这个问题并告诉 seam 始终注入(inject)本地接口(interface)?

我的 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() {

    }

}


最佳答案

我猜是下面的

 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 {}

你的 Stateless 应该是这样的

 /**
   * 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;

 }

关于java - 如何告诉 Seam 注入(inject)本地 EJB 接口(interface)(SLSB)而不是远程 EJB 接口(interface)(SLSB)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2720948/

相关文章:

java - 为什么Java中有些方法会修改原始值而有些则不会?

java - 如何在jni中链接静态库?

java - 从独立应用程序调用 glassfish ejb

java - 接缝奇怪的参数错误

java - 奇怪的 "String index out of range: 0"错误

java - 如何在java中的excel文件的同一张表中插入带有值的新行

java - 远程服务的 EJB 依赖注入(inject)在 Glassfish 上失败

java - 运行 EJB 示例项目时出现错误 500 : java. lang.NullPointerException

java - 如何根据用户时区更改时区

java - 将数据从 JSON ArrayList 加载到微调器中