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

时间:2010-04-27 12:03:19

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

我在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模式(< 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>  

即使在完成上述所有操作之后,接缝仍然会有时注入远程接口。我在这里错过了什么吗?任何人都可以告诉我如何解决这个问题,告诉缝始终注入本地接口?

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

    }

}


2 个答案:

答案 0 :(得分:7)

我想以下一个

 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;

 }

答案 1 :(得分:0)

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

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

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

非常感谢你的帮助!

- Harshad Vyawahare。