[英]CDI and EJB mix with glassfish 3.1
我在Glassfish上部署了兩個應用程序-應用程序A和B。
兩者均作為戰爭包部署,應用程序B使用應用程序A中的某些組件。
現在在應用程序AI中有一個接口:
public interface BusinessInterface() extends SomeOtherInterface {
void someAction();
}
我有3個此接口的實現-兩個在應用程序A中,一個在應用程序B中: BusinessInterfaceA1, BusinessInterfaceA2, BusinessInterfaceB
只要它們都是CDIBean,一切都很好-我使用自定義@Qualifier批注(@ BusinessInterfaceA1,@ BusinessInterfaceA2)和@Default批注,以實現B的實現以區分它們。
但是現在我需要兩個應用程序的A實現都必須是有狀態EJB,這才變得很有趣。
當我在兩個實現上都添加@Statefull批注時,我得到的是這樣的:
javax.servlet.ServletException: org.jboss.weld.exceptions.WeldException: WELD-000049
細節:
java.lang.IllegalStateException: Unable to convert ejbRef for ejb BusinessInterfaceA1 to a business object of type interface SomeOtherInterface
我該如何解決? 我需要所有實現都能夠以某種方式注入它們,例如
@Inject @SomeAnnotation private BusinessInterface businessInterface;
它是Glassfish 3.1中的錯誤 。 解決方法是用所有必需的接口標記實現,例如:
@Statefull/@Stateless
public class BusinessInterfaceImpl implements BusinessInterface, SomeOtherInterface {
// implementation
}
甚至BusinessInterface
擴展了SomeOtherInterface
,從Java規范來看,這樣做是無用的,但是作為該bug的變通辦法,它可以工作。
另一個解決方案是使用Glassfish 4.0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.