google / guava

Google core libraries for Java
Apache License 2.0
50.03k stars 10.86k forks source link

guava 14.0.1 cannot be deployed in a JEE7 Container #1433

Closed gissuebot closed 9 years ago

gissuebot commented 9 years ago

Original issue created by AaronJWhiteside on 2013-05-28 at 09:34 PM


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?

gissuebot commented 9 years ago

Original comment posted by hsaqallah on 2014-02-14 at 07:36 AM


The error message is: java.lang.NoSuchMethodError: com.google.common.base.Splitter.splitToList(Ljava/lang/CharSequence;)Ljava/util/List;

My mvn dependency:tree is showing exactly one guava 16.0 and I don't have google collections. This is the tree (minus our own packages): [INFO] +- org.springframework:spring-core:jar:3.2.5.RELEASE:compile [INFO] | - commons-logging:commons-logging:jar:1.1.1:compile [INFO] +- org.springframework:spring-web:jar:3.2.5.RELEASE:compile [INFO] | +- aopalliance:aopalliance:jar:1.0:compile [INFO] | +- org.springframework:spring-aop:jar:3.2.5.RELEASE:compile [INFO] | +- org.springframework:spring-beans:jar:3.2.5.RELEASE:compile [INFO] | - org.springframework:spring-context:jar:3.2.5.RELEASE:compile [INFO] +- org.springframework:spring-webmvc:jar:3.2.5.RELEASE:compile [INFO] | - org.springframework:spring-expression:jar:3.2.5.RELEASE:compile [INFO] +- org.springframework.data:spring-data-mongodb:jar:1.3.2.RELEASE:compile [INFO] | +- org.springframework:spring-tx:jar:3.1.4.RELEASE:compile [INFO] | +- org.springframework.data:spring-data-commons:jar:1.6.2.RELEASE:compile [INFO] | +- org.mongodb:mongo-java-driver:jar:2.10.1:compile [INFO] | - org.slf4j:jcl-over-slf4j:jar:1.7.1:runtime [INFO] +- junit:junit:jar:4.11:test [INFO] | - org.hamcrest:hamcrest-core:jar:1.3:test [INFO] +- org.mockito:mockito-all:jar:1.9.5:compile [INFO] +- org.springframework:spring-test:jar:3.2.5.RELEASE:compile [INFO] +- org.easytesting:fest-assert-core:jar:2.0M10:compile [INFO] | - org.easytesting:fest-util:jar:1.2.5:compile [INFO] +- org.apache.tomcat:tomcat-servlet-api:jar:7.0.47:provided [INFO] +- javax.servlet.jsp:jsp-api:jar:2.2:provided [INFO] +- javax.servlet.jsp.jstl:jstl-api:jar:1.2:compile [INFO] +- org.glassfish.web:jstl-impl:jar:1.2:compile [INFO] +- com.google.code.gson:gson:jar:2.2.4:compile [INFO] +- com.google.guava:guava:jar:16.0:compile [INFO] +- org.slf4j:slf4j-api:jar:1.7.5:compile [INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.5:compile [INFO] | - log4j:log4j:jar:1.2.17:compile [INFO] +- opensymphony:sitemesh:jar:2.4.2:compile [INFO] +- commons-codec:commons-codec:jar:1.4:compile [INFO] +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile [INFO] | - org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile [INFO] +- javax.mail:mail:jar:1.4.5:compile [INFO] | - javax.activation:activation:jar:1.1:compile [INFO] +- joda-time:joda-time:jar:2.3:compile

[INFO] - org.ocpsoft.prettytime:prettytime:jar:3.2.4.Final:compile

The same error is happening with guava 15.0.x and 16.0.1 Unless GlassFish 4.0 is including its own guava.

gissuebot commented 9 years ago

Original comment posted by pjpires on 2014-02-14 at 07:38 AM


Glassfish bundles its own Guava.

gissuebot commented 9 years ago

Original comment posted by hsaqallah on 2014-02-14 at 07:39 AM


Any idea how to remove it? Thanks.

gissuebot commented 9 years ago

Original comment posted by lukes@google.com on 2014-02-14 at 07:40 AM


This appears to be a different issue. Can you open a new bug?

gissuebot commented 9 years ago

Original comment posted by hsaqallah on 2014-02-14 at 07:48 AM


Done: https://github.com/google/guava/issues/1668

bcmedeiros commented 9 years ago

Why not remove just the @Singleton annotation, which causes the problem, and leaves the @Inject? At least Guice users will have to only set the scope to this class if they need that.

lukesandberg commented 9 years ago

@brunojcm That would probably have been more dangerous since then contains like Guice would create a new ServiceManager for each injection point and then some of them will fail because you can't construct a ServiceManager with started services.

in any case the annotations were removed and adding custom bindings for ServiceManager et.al. in your container should be straightforward