2010-04-27 71 views
2

我使用Seam和JBoss AS。 在我的應用程序中,我有一個SLSB,它也使用@Name註釋聲明爲seam組件。我正在嘗試使用@In註釋在另一個seam組件中注入和使用此SLSB。如何告訴Seam注入本地EJB接口(SLSB)而不是遠程EJB接口(SLSB)?

我的問題是,有時Seam注入本地接口(然後代碼運行正常),有時會接縫注入遠程接口(然後執行代碼時出現錯誤)。我曾嘗試做這一切鏈接指定的東西:http://docs.jboss.org/seam/2.2.0.GA/reference/en-US/html/configuration.html#config.integration.ejb.container

將SeamInterceptor配置,
我指定在components.xml文件中的JNDI模式(<核心:初始化調試=「真正的」 JNDI模式=」我已經嘗試使用@JndiName(「earName/ejbName/local」)註釋爲每個SLSB,
我已經嘗試設置此屬性(org.jboss。 seam.properties文件中的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始終注入本地接口?

我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="@[email protected]"/> 
    <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() { 

    } 

} 

 
+0

我檢查了jboss日誌,我在日誌文件中觀察到這一行:DEBUG [org.jboss.seam.Component](main)org。jboss.seam.core.init.jndiPattern = myEarName /#{ejbName}/local, jndiPattern正在正確設置。 – 2010-04-28 07:11:43

+0

V看起來不錯!嘗試以下方法:**移除遠程界面**,並查看您的應用程序是否正常運行。如果沒有,請顯示您的stackTrace。如果可能,請不要使用AutoCreate註釋。 – 2010-04-28 13:59:49

+0

@Arthur Ronald F D Garcia:好的,我刪除了AutoCreate註釋,並用@In(create = true)替換它。我刪除了所有的遠程接口,並運行應用程序6次(因爲即使使用遠程接口,應用程序有時也能正常工作),它在6次運行都很順利。我覺得用這個遠程接口去掉seam並不會感到困惑,使用哪個接口,本地還是遠程。 – 2010-04-29 06:28:44

回答

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

你無國籍的笑ULD看起來像

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

} 
+0

Arthur,謝謝你的詳細回覆,但我正在做你提到的同樣的事情,但我仍然面臨這個問題。 – 2010-04-28 04:29:14

+0

@Harshad V所以我需要你展示你的應用程序的樣子:*/WEB-INF/components.xml *,你的EJB組件,請參閱http://stackoverflow.com/questions/2453746/jboss-seam-enabling-debug -page-on-weblogic-10-3-2-11g/2459795#2459795你的應用應該如何看起來像。你使用哪個App服務器? – 2010-04-28 05:57:19

+0

我正在使用JBoss 5.1.0.GA App服務器。我檢查了您提供的鏈接,我的應用看起來像鏈接上指定的鏈接,除了myapp-ejb.jar文件夾中沒有lib文件夾,myapp-war.war文件夾中的lib文件夾位於WEB-INF文件夾內,即myapp-war.war \ WEB-INF \ lib。我上面編輯了我的問題,並添加了我的components.xml和EJB組件。 – 2010-04-28 10:03:56

0

@Arthur羅納德˚Fd加西亞:我的壞,我不理你上面張貼的答案的一小部分。

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

當我創建一個MyStateless父接口時,將抽象方法從本地和遠程接口移動到父接口(以使本地和遠程接口爲空),錯誤得到解決,現在我的應用程序正常工作!

非常感謝您的幫助!

- 哈薩德Vyawahare。