tree: 1d86fd6e266c2ef1a03ffb6631d06a2461dbc6fe [path history] [tgz]
  1. src/
  2. pom.xml
  3. README.MD
examples/cdi-webapp/README.MD

Jersey CDI Integration CDI Beans WebApp Example

This example demonstrates how to develop RESTful web service with CDI managed beans and a Servlet 3.0 Web container.

Contents

The mapping of the URI path space is presented in the following table:

URI pathDescriptionExpected Results
/cdi-webapp/helloworldA managed bean with no use of injection whatsoeverHello World
/cdi-webapp/singletonShows injection of context objects into the fields of a managed bean.OK GET /cdi-webapp/singleton
/cdi-webapp/singleton/counterShows injection of context objects into the fields of a managed bean.standalone Grizzly (no resource injection support) - 0 initial increment value, that gets incremented with each other request
  Java EE compliant AS - 42 initial increment value
/cdi-webapp/other/C/DShows injection of context objects and path parameters into the fields of a managed bean.INTERCEPTED: OK GET /cdi-webapp/other, c=C, d=D
/cdi-webapp/echofield/b?a=aShows injection of path and query parameters into the fields of a managed bean.ECHO a b
/cdi-webapp/echo/aA managed bean that uses (but does not inject) a path parameter.ECHO a

Running the Example

This example should work on any Java EE 7 compliant application server. It has been tested on a standalone GlassFish 4 instance. The easiest way to get the application running there is to build it and deploy as follows:

mvn clean package
$AS_HOME/asadmin deploy target/cdi-webapp.war

Another option, introduced in Jersey 2.15, is to run this example in Grizzly HTTP server. To get the application running there you just invoke the following command:

mvn clean compile exec:java

Since Weld Servlet support is provided also for Apache Tomcat server, there is yet another way how to deploy the application. Use the tomcat-packaging maven profile to get the WAR archive packaged in a way that makes it ready for Tomcat 7+ deployment:

mvn -Ptomcat-packaging clean package
cp target/cdi-webapp.war $CATALINA_HOME/webapps

After you successfully deploy the application, visit the following URLs: