[GLASSFISH-20484] Cannot Perform CDI Created: 08/May/13  Updated: 09/May/13  Resolved: 08/May/13

Status: Resolved
Project: glassfish
Component/s: cdi
Affects Version/s: 4.0_b83
Fix Version/s: None

Type: Bug Priority: Major
Reporter: agksmehx Assignee: jjsnyder83
Resolution: Works as designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Fedora 18 running as plugin under Eclipse Kepler M6



 Description   

I am trying to run a particularly simple test case using the latest promoted build of Glassfish 4.0. I have tried placing META-INF/beans.xml in all possible permutations including its own jar in WEB-INF/lib

The best I get is the following errors with a layout+sources that are listed after it:

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
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 106 milliseconds.

Layout:

$ jar tvf cdibug.war
0 Tue May 07 23:19:48 HST 2013 META-INF/
68 Tue May 07 23:19:48 HST 2013 META-INF/MANIFEST.MF
0 Tue May 07 23:14:20 HST 2013 META-INF/beans.xml
0 Tue May 07 23:19:32 HST 2013 WEB-INF/
0 Tue May 07 23:18:58 HST 2013 WEB-INF/classes/
0 Tue May 07 22:51:54 HST 2013 WEB-INF/classes/com/
0 Tue May 07 22:51:54 HST 2013 WEB-INF/classes/com/example/
0 Tue May 07 23:09:34 HST 2013 WEB-INF/classes/com/example/cdibug/
174 Tue May 07 22:54:28 HST 2013 WEB-INF/classes/com/example/cdibug/Test.java
171 Tue May 07 22:54:04 HST 2013 WEB-INF/classes/com/example/cdibug/App.java
309 Tue May 07 22:56:30 HST 2013 WEB-INF/classes/com/example/cdibug/Foo.java
398 Tue May 07 23:06:00 HST 2013 WEB-INF/classes/com/example/cdibug/Test.class
304 Tue May 07 23:06:00 HST 2013 WEB-INF/classes/com/example/cdibug/App.class
634 Tue May 07 23:06:00 HST 2013 WEB-INF/classes/com/example/cdibug/Foo.class
$

Source of `beans.xml`:

$ cat META-INF/beans.xml # EMPTY 0 bytes

Source of `App.java`:

$ 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 {
}

Source of `Test.java`:

$ cat WEB-INF/classes/com/example/cdibug/Test.java
package com.example.cdibug;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("/test")
public class Test {
@GET
public String greet ()

{ return "hello"; }

}

Source of `Foo.java`:

$ 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()"); }

}



 Comments   
Comment by agksmehx [ 08/May/13 ]

Also posted on Stackoverflow (check for answers + better formatting): http://stackoverflow.com/questions/16437146/cannot-perform-cdi-in-glassfish-4-0

Comment by jjsnyder83 [ 08/May/13 ]

beans.xml can reside in either WEB-INF or WEB-INF/classes/META-INF. Most people place it in WEB-INF.

If you're still having trouble with the application please reopen this issue and send the application (with source) to me: j.j.snyder@oracle.com

Comment by agksmehx [ 08/May/13 ]

following email sent with attachment

I tried putting beans.xml in WEB-INF and also in WEB-INF/classes/META-INF. I slightly modified the test case to be sure there was a problem.

The attached cdibug.war contains both source and classes. The following command out is for your convenience.

$ 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

Comment by agksmehx [ 09/May/13 ]

Update: please ignore; works fine in glassfish-4.0-b87 It was not working in the version bundled with Eclipse Kepler m06. Sorry for the bother.

Generated at Sun Sep 25 03:25:15 UTC 2016 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.