users@glassfish.java.net

Re: Cannot perform CDI in Glassfish 4.0.0.201304141926

From: agks mehx <agksmehx_at_gmail.com>
Date: Wed, 8 May 2013 20:13:41 -1000

Update: please ignore; works fine in glassfish-4.0-b87


On Wed, May 8, 2013 at 1:53 PM, agks mehx <agksmehx_at_gmail.com> wrote:

> Hi,
>
> I am having trouble with an extremely simplified CDI example in Glassfish
> 4.0 which I downloaded from with Eclipse Kepler. The version seems to be
> the one built on 14 April 2013.
>
> It smells like a Glassfish bug but I wanted to verify on the users list
> before re-opening it on JIRA.
>
> The following output shows all parts. I have a .war file which I could
> attach but I am not sure it would go through the mailing list.
>
> Any advice is appreciated.
>
> ===============
>
> I originally placed beans.xml in ./META-INF/ (i. e. not in WEB-INF). That
> was the only location where CDI showed any sign of life. But it seemed to
> want to scan classes with a weird prefix. The messages were:
>
> WARNING: Error while trying to load Bean Class WEB-INF.classes.com.example.
> cdibug.Test : java.lang.ClassNotFoundException:
> WEB-INF.classes.com.example.cdibug.Test
> WARNING: Error while trying to load Bean Class
> WEB-INF.classes.com.example.cdibug.Foo : java.lang.ClassNotFoundException:
> WEB-INF.classes.com.example.cdibug.Foo
> WARNING: Error while trying to load Bean Class
> WEB-INF.classes.com.example.cdibug.App : java.lang.ClassNotFoundException:
> WEB-INF.classes.com.example.cdibug.App
>
> Then I tried placing beans.xml in WEB-INF and also in
> WEB-INF/classes/META-INF. That case is described below and I doubt if CDI
> was getting started at all in those cases.
>
> Either I am doing something stupid or there is a significant bug in
> Glassfish.
>
> Details:
>
> $ jar cvf ../cdibug.war .
> added manifest
> adding: WEB-INF/(in = 0) (out= 0)(stored 0%)
> adding: WEB-INF/beans.xml(in = 255) (out= 154)(deflated 39%)
> adding: WEB-INF/classes/(in = 0) (out= 0)(stored 0%)
> adding: WEB-INF/classes/com/(in = 0) (out= 0)(stored 0%)
> adding: WEB-INF/classes/com/example/(
> in = 0) (out= 0)(stored 0%)
> adding: WEB-INF/classes/com/example/cdibug/(in = 0) (out= 0)(stored 0%)
> adding: WEB-INF/classes/com/example/cdibug/Test.java(in = 232) (out=
> 156)(deflated 32%)
> adding: WEB-INF/classes/com/example/cdibug/Foo.java(in = 309) (out=
> 187)(deflated 39%)
> adding: WEB-INF/classes/com/example/cdibug/App.java(in = 171) (out=
> 118)(deflated 30%)
> adding: WEB-INF/classes/com/example/cdibug/Test.class(in = 475) (out=
> 321)(deflated 32%)
> adding: WEB-INF/classes/com/example/cdibug/App.class(in = 304) (out=
> 235)(deflated 22%)
> adding: WEB-INF/classes/com/example/cdibug/Foo.class(in = 634) (out=
> 439)(deflated 30%)
>
> $ cat WEB-INF/classes/META-INF/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" xsi:schemaLocation="
> http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
> </beans>
>
> $ cat WEB-INF/classes/com/example/cdibug/Foo.java
> package com.example.cdibug;
>
> import java.util.logging.Logger;
>
> import javax.enterprise.context.ApplicationScoped;
>
> @ApplicationScoped
> public class Foo {
> public Foo () {
> System.out.println("stdout: Foo()");
> System.err.println("stderr: Foo()");
> Logger.getGlobal().info("global_log: Foo()");
> }
> }
>
> $ cat WEB-INF/classes/com/example/cdibug/App.java
> package com.example.cdibug;
>
> import javax.ws.rs.ApplicationPath;
> import javax.ws.rs.core.Application;
>
> @ApplicationPath("/rest")
> public class App extends Application {
> }
>
> $ cat WEB-INF/classes/com/example/cdibug/Test.java
> package com.example.cdibug;
>
> import javax.inject.Inject;
>
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
>
> @Path("/test")
> public class Test {
> @Inject
> public Foo foo;
>
> @GET
> public String greet () {
> return "hello";
> }
> }
>
> I upload the war to glassfish via management console with all defaults.
> The glassfish log contains:
>
> INFO: Registering the Jersey servlet application, named
> com.example.cdibug.App, at the servlet mapping /rest/*, with the
> Application class of the same name.
> INFO: Loading application [cdibug] at [/cdibug]
> INFO: cdibug was successfully deployed in 147 milliseconds.
>
> Then I use a browser to access: http://localhost:8080/cdibug/rest/test
>
> That causes an exception, seeming to indicate that the class scanning
> needed for introspection did not happen:
>
> INFO: Initiating Jersey application, version Jersey: 2.0-m12-1 2013-02-15
> 10:05:31...
> WARNING: StandardWrapperValve[com.
> example.cdibug.App]: Servlet.service() for servlet com.example.cdibug.App
> threw exception
> org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object
> available for injection at
> Injectee(requiredType=Foo,parent=Test,qualifiers={}),position=-1,optional=false,self=false,unqualified=null,913957636)
> at
> org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:74)
> at org.jvnet.hk2.internal.ClazzCreator.resolve(ClazzCreator.java:174)
> at
> org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:197)
> at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:294)
> at
> org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:433)
> at
> org.glassfish.jersey.process.internal.RequestScope.findOrCreate(RequestScope.java:157)
> at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2099)
> at
> org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:570)
> at
> org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:557)
> at
> org.glassfish.jersey.internal.inject.Injections.getOrCreate(Injections.java:193)
> at
> org.glassfish.jersey.server.model.MethodHandler$ClassBasedMethodHandler.getInstance(MethodHandler.java:185)
> at
> org.glassfish.jersey.server.internal.routing.PushMethodHandlerRouter.apply(PushMethodHandlerRouter.java:105)
> at
> org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:118)
> at
> org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:121)
> at
> org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:121)
> at
> org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:121)
> at
> org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:102)
> at
> org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:62)
> at
> org.glassfish.jersey.process.internal.Stages.process(Stages.java:197)
> at
> org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:198)
> at
> org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
> at
> org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:183)
> at
> org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:852)
> at
> org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:321)
> at
> org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:372)
> at
> org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:335)
> at
> org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:218)
> at
> org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
> at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:342)
> at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
> at
> org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
> at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
> at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:176)
> at
> org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
> at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
> at
> com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
> at
> org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:164)
> at
> org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:175)
> at
> org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
> at
> org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:273)
> at
> org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
> at
> org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:134)
> at
> org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
> at
> org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
> at
> org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:820)
> at
> org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
> at
> org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
> at
> org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
> at
> org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
> at
> org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
> at
> org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
> at java.lang.Thread.run(Thread.java:722)
>
> Placing beans.xml in WEB-INF/classes/META-INF results in exact same
> situation as above.
>
> Placing beans.xml in ./META-INF/beans.xml (outside WEB-INF), as reported
> in the bug, is the only one that shows any sign of life from CDI scanning,
> and results in the following anomalous output as well as the above
> exception.
> WARNING: Error while trying to load Bean Class WEB-INF.classes.com.example.
> cdibug.Test : java.lang.ClassNotFoundException:
> WEB-INF.classes.com.example.cdibug.Test
> WARNING: Error while trying to load Bean Class
> WEB-INF.classes.com.example.cdibug.Foo : java.lang.ClassNotFoundException:
> WEB-INF.classes.com.example.cdibug.Foo
> WARNING: Error while trying to load Bean Class
> WEB-INF.classes.com.example.cdibug.App : java.lang.ClassNotFoundException:
> WEB-INF.classes.com.example.cdibug.App
>
>