2013-03-12 69 views
0

我有一個JavaEE6應用具有以下結構:注入豆成過濾器進行包裝共享庫

app.ear 
    META-INF 
    application.xml 
    lib 
    commmon-server-lib.jar 
    webapp1.war 
    webapp2.war 
    services-ejb.jar 

雙方的webapps在其MANIFEST.MF中的Class-Path條目的通用服務器,lib.jar (骨感的戰爭)。

的application.xml:

<application> 
    <module> 
    <ejb>services-ejb.jar</ejb> 
    </module> 
    <module> 
    <web> 
     <web-uri>webapp1.war</web-uri> 
     <context-root>/webapp1</context-root> 
    </web> 
    </module> 
    <module> 
    <web> 
     <web-uri>webapp2.war</web-uri> 
     <context-root>/webapp2</context-root> 
    </web> 
    </module> 
    <library-directory>lib</library-directory> 
</application> 

common-server-lib.jar有一個網絡過濾器,應該有一些EJB和其他CDI管理注入豆。這個過濾器在兩個webapps的web.xml中定義。

common-server-lib.jar和戰爭的beans.xml在適當的地方。

現在的問題是,當我嘗試部署此應用程序到GlassFish,我得到象這樣的錯誤:

Class [ Lcom/acme/UserService; ] not found. Error while loading 
    [ class com.acme.filter.MyFilter ] 

UserService服務位於服務-ejb.jar

所以我的問題是: 我究竟做錯了什麼...?在共享庫中定義Web組件(針對它的依賴關係使用注入)有什麼問題嗎?

編輯:

在JSR-315(Servlet的3.0最終規範)第15.5可以發現:

In a web application, classes using resource injection will have their annotations 
processed only if they are located in the WEB-INF/classes directory, or if they are 
packaged in a jar file located in WEB-INF/lib. 

我搬到共服務器庫。 jar到兩個webapps的WEB-INF/lib目錄,但我仍然有同樣的問題;/...

回答

0

經過這個難題掙扎了很多小時我f ound一個解決方案:

  1. 添加web-fragment.xmlcommmon-server-lib.jar與我的過濾器
  2. 刪除過濾器規格從web應用web.xml
  3. 變化行家fonfiguration從WEB-INF/lib 目錄中刪除所有jar的除了commmon-server-lib.jar
  4. 從刪除commmon-server-lib.jar EAR /lib目錄