Giter Club home page Giter Club logo

tomcat-weld-resteasy's Introduction

Java 8 web application using Embedded Tomcat, Weld and RESTEasy

Also as a bonus there is a JSP and a Servlet.

Introduction

A working example of a Springboot equivalent for CDI is neither as easy to find nor construct as one might expect.

Nevertheless, this application demonstrates more or less the minimum needed to have CDI (Weld), Tomcat (embedded) and RESTEasy all running in harmony.

Build and package

From the weld-boot project fodler, build and package with the plugin already provided in the POM:

mvn package

Then you may run (from the project root directory) with:

target\bin\webapp.bat

You can of course run from an IDE. Just locate launch.Main.java.

Go to http://localhost:8889/ to start with the home page.

Resources

Some reasonably essential reading:

Notes

Notes on the experience:

  • A good approach is to clone the example provided courtesy of Heroku on Github. Start with that, get it working and then modify as necessary.
  • Jersey: Painful to merely get the correct dependencies in a CDI environment. Abandoned and went with RESTEasy.
  • RESTEasy-CDI Integration gives a clue about getting RESTEasy and CDI working on Pre-Servlet 3 containers. It was necessary to have a web.xml in place in order for JAX-RS managed entities to permit injection of CDI managed resources. Chapter 40. CDI Integration explains why CDI and JAX-RS are not compatible by default and thus it becomes necessary to bridge the gap with the resteasy-cdi module.
  • Weld is supposed to work with Jetty but documentation and online material seems to be a little thin. Most CDI users are likely to be enterprise customers deploying to JBoss or some other JEE container and so most of the material online will help with these cases. Very little on Jetty but more on Tomcat so go with Tomcat, which can be embedded just as Jetty can.
  • Example in the Weld documentation for embedding Tomcat just did not work. org.jboss.weld.environment.servlet.Listener is not required at all despite the fact that it states "With embedded Tomcat it is necessary to register Weld's listener programmatically". But then notice how the pertinent line in the code example is commented out. It almost looks like a mistake and therefore tempting to uncomment. If you copied and pasted blindly you would be fine but in any case it appears not to be required. It was necessary however to have /WEB-INF/beans.xml and /META-INF/context.xml in place.
  • JMS with JNDI documentation sparse for Tomcat and embedded Tomcat at that. Need to configure web.xml and context.xml and enable JNDI (tomcat.enableNaming()).

tomcat-weld-resteasy's People

Contributors

chrisjleu avatar

Stargazers

Hemant Bothra avatar Adrián Alvarado Ramírez avatar Christophe Thiebaud avatar Andrew NS Yeow avatar Xuan Thuy Dang avatar Alex Rodin avatar

Watchers

James Cloos avatar  avatar premprakashrohan avatar Danilo Magalhães avatar Alessandro Moura avatar Adrián Alvarado Ramírez avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.