`
newjunwei
  • 浏览: 10970 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

About guava cannot be deployed in a JEE7 Container

阅读更多
guava 15.0 版本无法部署在glassfish3.1.2.2上,经过查找原因是关于javaEE7 CDI模式开启造成的,在guava issues 1433找到线索。
地址:https://code.google.com/p/guava-libraries/issues/detail?id=1433
简介:
In JEE7 CDI (CDI 2.0) is enabled by default (without a beans.xml needing to be present), with no standardized way of disable it.

com.google.common.util.concurrent.ServiceManager is annotated with @Singleton and has a constructor...

  @Inject ServiceManager(Set<Service> services) {
    this((Iterable<Service>) services);
  }

So any war or ear that contains a guava 14.0.1 jar suffers from CDI seeing this and trying to create the bean but failing and thus failing the entire war from loading.

This error is from Glassfish 4.0

[2013-05-23T15:08:35.664-0700] [glassfish 4.0] [SEVERE] [] [javax.enterprise.system.core] [tid: _ThreadID=34 _ThreadName=admin-listener(2)] [timeMillis: 1369346915664] [levelValue: 1000] [[
  Exception while loading the app : CDI deployment failure:WELD-001408 Unsatisfied dependencies for type [Set<Service>] with qualifiers [@Default] at injection point [[BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject com.google.common.util.concurrent.ServiceManager(Set<Service>)]
org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Set<Service>] with qualifiers [@Default] at injection point [[BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject com.google.common.util.concurrent.ServiceManager(Set<Service>)]

The same WAR also fails to deploy on Firefly 8.0 with a similar error.

Can guava be modified to not use the @Singleton and @Inject annotations?
也就是说,guava14.0.1版本在部署在glassfish 4.0上时会出类似问题,然后根据回复发现,guava15.0单独为了解决这个问题被加入了一个beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
       bean-discovery-mode="none">
</beans>
这样,guava15.0便可以在glassfish4.0(支持javaEE7)上发布,但是仍不支持3.1.2.2(Oracle官方版本现在只有3.1.2.2),回复中有遇到相同问题的,最后将beans.xml换为一下,便可以支持两个版本了:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:weld="http://jboss.org/schema/weld/beans"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd
                           http://jboss.org/schema/weld/beans http://jboss.org/schema/weld/beans_1_1.xsd">

    <weld:scan>
        <weld:exclude name="com.google.**"/>
    </weld:scan>
</beans>
glassfish4.0 是刚发布的版本,这是首个兼容 Java EE 7 企业级标准的应用服务器,下图是 Java EE 7 的 API 版本规范:


根据回复,guava在16版本会通过删掉inject来彻底解决这个问题,而CDI guys 却把这个当作good bug,可能短时间内不改,关注guava新版本,这样就不用手动改动jar包来解决问题了。另外,glassfish 3.1.2.2考虑升级到  GlassFish 4 Open Source Edition

So, both guava-14.0.1 and (strangely enough) guava-15.0-cdi1.0 *are* CDI agnostic. They only use JSR-330 annotations. To be clear: CDI itself is the problem here, because its specification prevents the use of libraries that annotate classes with certain JSR-330 annotations.

We're removing the annotations in Guava 16.0 because we feel that A) it seems unlikely that CDI will fix its spec anytime soon, and B) the problems this causes for users in CDI environments (where there apparently isn't any good workaround) probably outweighs the benefits of the annotations to users who are taking advantage of them in other environments (because at least with other JSR-330 frameworks like Guice and Dagger, binding the ServiceManager yourself isn't hard). It's not because we believe it's wrong for Guava to use the annotations; quite the opposite.
最终解决方案确定为删除guava 中的beans.xml,因为glassfish3.1.2.2是javaee6
分享到:
评论

相关推荐

    Google中的Guava源码

    Guava is a set of core Java libraries from Google that includes new collection types (such as multimap and multiset), immutable collections, a graph library, and utilities for concurrency, I/O, ...

    guava-18.0(guava-18.0.jar和guava-18.0-sources.jar)

    7. **流处理**:Guava的FluentIterable和Iterables提供了一种更流畅的迭代器操作方式,便于链式调用。 8. **事件监听**:Guava的EventBus可以方便地实现发布/订阅模式,简化事件驱动的编程。 9. **枚举集与常量**:...

    guava-23.0.zip guava.jar guava

    在标题和描述中提到的"guava-23.0.zip"是一个包含Guava库版本23.0的压缩文件,而"guava.jar"则是Guava库的JAR文件,"guava"可能指的是Guava库本身或者与其相关的其他内容。 Guava库的核心特性包括: 1. **集合框架...

    guava-r09-jarjar.jar

    7. **流(Stream)**:虽然Guava的流API是在Java 8 Stream API之前提供的,但它提供了一些额外的功能,如Peekable和Iterators.peek()。 8. **Optional**:Guava的Optional类在Java 8之前就引入了可空值的概念,用来...

    guava-31.1-jre.jar

    guava

    guava源文档

    guava源文档guava源文档guava源文档guava源文档guava源文档guava源文档guava源文档guava源文档guava源文档guava源文档guava源文档guava源文档guava源文档guava源文档guava源文档guava源文档guava源文档guava源文档...

    guava-19.0 jar和sources

    Guava是Google开发的一个核心库,它为Java平台提供了许多实用工具类,极大地丰富了标准库的功能。在Java开发中,Guava库被广泛使用,因为它包含了大量的集合框架、并发支持、缓存机制、字符串处理、I/O操作等多个...

    guava-23.0-API文档-中文版.zip

    赠送jar包:guava-23.0.jar; 赠送原API文档:guava-23.0-javadoc.jar; 赠送源代码:guava-23.0-sources.jar; 赠送Maven依赖信息文件:guava-23.0.pom; 包含翻译后的API文档:guava-23.0-javadoc-API文档-中文...

    guava-17.0-API文档-中文版.zip

    赠送jar包:guava-17.0.jar; 赠送原API文档:guava-17.0-javadoc.jar; 赠送源代码:guava-17.0-sources.jar; 赠送Maven依赖信息文件:guava-17.0.pom; 包含翻译后的API文档:guava-17.0-javadoc-API文档-中文...

    guava-20.0-API文档-中文版.zip

    赠送jar包:guava-20.0.jar; 赠送原API文档:guava-20.0-javadoc.jar; 赠送源代码:guava-20.0-sources.jar; 赠送Maven依赖信息文件:guava-20.0.pom; 包含翻译后的API文档:guava-20.0-javadoc-API文档-中文...

    guava-18.0-API文档-中文版.zip

    赠送jar包:guava-18.0.jar; 赠送原API文档:guava-18.0-javadoc.jar; 赠送源代码:guava-18.0-sources.jar; 包含翻译后的API文档:guava-18.0-javadoc-API文档-中文(简体)版.zip 对应Maven信息:groupId:...

    guava多个版本jar包

    这个压缩包包含的是Guava的不同版本,分别是guava-2.6.2.jar、guava-18.0.jar、guava-19.0.jar和guava-23.0.jar。每个版本都有其特定的功能和改进,让我们逐一探讨这些版本的关键特性。 1. guava-2.6.2.jar:这是...

    最新版 guava-30.1-jre.jar

    最新版 guava-30.1-jre.jar

    不加密Google Guava视频教程.txt

    ├─Google Guava 第01讲-Joiner详细介绍以及和Java8Collector对比.wmv ├─Google Guava 第02讲-Guava Splitter详细讲解以及实战练习.wmv ├─Google Guava 第03讲-Preconditions&Objects;&assert;讲解.wmv ├─...

    guava-11.0.2-API文档-中文版.zip

    赠送jar包:guava-11.0.2.jar; 赠送原API文档:guava-11.0.2-javadoc.jar; 赠送源代码:guava-11.0.2-sources.jar; 赠送Maven依赖信息文件:guava-11.0.2.pom; 包含翻译后的API文档:guava-11.0.2-javadoc-API...

    Android代码-guava

    Guava is a set of core libraries that includes new collection types (such as multimap and multiset), immutable collections, a graph library, functional types, an in-memory cache, and APIs/utilities ...

    google开源项目guava.jar包

    谷歌的Guava库是Java开发中的一个非常重要的开源项目,它提供了一系列的高效、实用的工具类,大大简化了常见的编程任务。Guava的核心特性包括集合框架、缓存、原生类型支持、并发库、字符串处理、I/O操作等。这个...

    guava-26.0-jre.zip

    Guava是Google为Java平台设计并维护的一个开源库,它提供了许多高级功能和实用工具,极大地增强了Java开发的效率和代码质量。Guava 26.0-jre版本是针对Java运行时环境(JRE)优化的一个特定版本,旨在更好地支持Java...

    guava-21.0-rc2 、guava-21.0-rc2-javadoc 、guava-21.0-rc2-sources

    这里提到的"guava-21.0-rc2"、"guava-21.0-rc2-javadoc"和"guava-21.0-rc2-sources"分别代表了Guava库的21.0 Release Candidate 2版本的不同组成部分。 1. **guava-21.0-rc2**: 这是Guava库的二进制发行版,包含了...

    Guava 工程项目包 有实例

    Guava 是一个由 Google 开发并维护的 Java 库,它提供了许多实用工具类和集合框架的增强功能,极大地丰富了 Java 平台的标准库。Guava 的目标是解决 Java 开发人员在日常工作中遇到的各种常见问题,提高开发效率和...

Global site tag (gtag.js) - Google Analytics