【问题标题】:Injecting beans into filter packaged in a shared library将 bean 注入到共享库中打包的过滤器中
【发布时间】:2013-03-12 07:30:13
【问题描述】:

我有一个具有以下结构的 JavaEE6 应用程序:

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

两个 webapp 在其 MANIFEST.MF(瘦战)的 Class-Path 条目中都有 common-server-lib.jar。

应用程序.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 中有一个Web 过滤器,应该注入很少的EJB 和其他CDI 托管bean。此过滤器在两个 web 应用的 web.xml 中定义。

common-server-lib.jar 和战争的 beans.xml 在适当的位置。

现在的问题是,当我尝试将此应用程序部署到 Glassfish 时,我收到如下错误:

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

UserService服务位于services-ejb.jar

所以我的问题是:我做错了什么......?在共享库中定义 Web 组件(对其依赖项使用注入)有什么问题吗?

编辑:

在 JSR-315(Servlets 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.

我已将 common-server-lib.jar 移至两个 webapps 的 WEB-INF/lib 目录,但我仍然遇到同样的问题;/...

【问题讨论】:

    标签: java-ee-6 cdi servlet-filters ejb-3.1


    【解决方案1】:

    在解决这个难题数小时后,我找到了解决方案:

    1. 使用我的过滤器将web-fragment.xml 添加到commmon-server-lib.jar
    2. 从 webapps web.xml's 中删除过滤器规范
    3. 更改 maven 配置以从 WEB-INF/lib 中删除所有 jar commmon-server-lib.jar 以外的目录
    4. 从 EAR /lib 目录中删除 commmon-server-lib.jar

    【讨论】:

      猜你喜欢
      • 2016-07-20
      • 1970-01-01
      • 2016-11-09
      • 2010-09-28
      • 1970-01-01
      • 2011-04-20
      • 2017-11-08
      • 1970-01-01
      • 2013-01-07
      相关资源
      最近更新 更多