title: RESTEasy JAX-RS Nullpointer when I try to reach my Controller class from another package
body: <p>I'm setting up a Maven project (in Java EE) based on a basic BCE-Pattern.
  Within the &quot;Boundary&quot;-Package i started to specify several JAX-RS Apis using RESTeasy.
  If I send a POST, GET or whatever to this APIs they should delegate the request to the controller classes which then basically do all the work.</p>
  <p>But whenever the Boundary (Api) sends a request to the Controller (Service) I face Nullpointer Exceptions like:</p>
  <pre><code>2020-07-02T13:45:15.987+0200|Info: Try to post User alexhuckerman
  2020-07-02T13:45:15.994+0200|Warning: StandardWrapperValve[Resteasy]: Servlet.service() for servlet Resteasy threw exception
  org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
      at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:106)
      at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:372)
      at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:216)
      at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:515)
      at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:259)
      at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:160)
      at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
      at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:163)
      at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:245)
      at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:249)
      at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:60)
      at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:750)
      at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1540)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:119)
      at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:611)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:550)
      at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:114)
      at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:199)
      at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:463)
      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:168)
      at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
      at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
      at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:242)
      at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
      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:539)
      at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
      at java.lang.Thread.run(Thread.java:748)
  Caused by: java.lang.NullPointerException
      at boundary.UserApi.postUser(UserApi.java:57)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:167)
      at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:130)
      at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:638)
      at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:504)
      at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:454)
      at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
      at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:456)
      at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:417)
      at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:391)
      at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:68)
      at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:488)
      ... 37 more
  </code></pre>
  <p><strong>My POM.xml</strong></p>
  <pre><code>&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
  xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
  xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;com.wm&lt;/groupId&gt;
  &lt;artifactId&gt;workflowManager&lt;/artifactId&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;name&gt;workflowManager Maven Webapp&lt;/name&gt;
  &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
  &lt;dependencies&gt;
  
      &lt;!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-core --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
          &lt;artifactId&gt;resteasy-core&lt;/artifactId&gt;
          &lt;version&gt;4.5.5.Final&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-client --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
          &lt;artifactId&gt;resteasy-client&lt;/artifactId&gt;
          &lt;version&gt;4.5.5.Final&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-servlet-initializer --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
          &lt;artifactId&gt;resteasy-servlet-initializer&lt;/artifactId&gt;
          &lt;version&gt;4.5.5.Final&lt;/version&gt;
      &lt;/dependency&gt;
      
          &lt;!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxrs --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
          &lt;artifactId&gt;resteasy-jaxrs&lt;/artifactId&gt;
          &lt;version&gt;3.12.1.Final&lt;/version&gt;
      &lt;/dependency&gt; 
  
  
      &lt;!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jackson-provider --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
          &lt;artifactId&gt;resteasy-jackson-provider&lt;/artifactId&gt;
          &lt;version&gt;3.12.1.Final&lt;/version&gt;
      &lt;/dependency&gt; 
      
      &lt;dependency&gt;
          &lt;groupId&gt;junit&lt;/groupId&gt;
          &lt;artifactId&gt;junit&lt;/artifactId&gt;
          &lt;version&gt;3.8.1&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax&lt;/groupId&gt;
          &lt;artifactId&gt;javaee-api&lt;/artifactId&gt;
          &lt;version&gt;7.0&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.ws.rs&lt;/groupId&gt;
          &lt;artifactId&gt;javax.ws.rs-api&lt;/artifactId&gt;
          &lt;version&gt;2.1.1&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.persistence&lt;/groupId&gt;
          &lt;artifactId&gt;javax.persistence-api&lt;/artifactId&gt;
          &lt;version&gt;2.2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- https://mvnrepository.com/artifact/com.ibm.db2/jcc --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.ibm.db2&lt;/groupId&gt;
          &lt;artifactId&gt;db2jcc&lt;/artifactId&gt;
          &lt;version&gt;1.0.2&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.5.1&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;source&gt;1.8&lt;/source&gt; &lt;!-- or higher, depending on your project --&gt;
                  &lt;target&gt;1.8&lt;/target&gt; &lt;!-- or higher, depending on your project --&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.glassfish.maven.plugin&lt;/groupId&gt;
              &lt;artifactId&gt;maven-glassfish-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.1&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;glassfishDirectory&gt;C:\Users\AlexanderCimander\Documents\Master@IBM\Uni\glassfish5\glassfish&lt;/glassfishDirectory&gt;
                  &lt;user&gt;admin&lt;/user&gt;
                  &lt;passwordFile&gt;files\password.txt&lt;/passwordFile&gt;
                  &lt;domain&gt;
                      &lt;name&gt;domain1&lt;/name&gt;
                      &lt;host&gt;localhost&lt;/host&gt;
                      &lt;adminPort&gt;4848&lt;/adminPort&gt;
                  &lt;/domain&gt;
                  &lt;components&gt;
                      &lt;component&gt;
                          &lt;name&gt;${project.artifactId}&lt;/name&gt;
                          &lt;artifact&gt;${project.build.directory}/${project.build.finalName}.war&lt;/artifact&gt;
                      &lt;/component&gt;
                  &lt;/components&gt;
              &lt;/configuration&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;deploy&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.3.0&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;archive&gt;
                      &lt;addMavenDescriptor&gt;false&lt;/addMavenDescriptor&gt;
                  &lt;/archive&gt;
                  &lt;strong&gt;
                      &lt;archiveClasses&gt;false&lt;/archiveClasses&gt;
                  &lt;/strong&gt;
                  &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
              &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;1.2.1&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;executable&gt;C:XXXXX\glassfish5\glassfish\bin\asadmin.bat&lt;/executable&gt;
                  &lt;arguments&gt;
                      &lt;argument&gt;--host=localhost&lt;/argument&gt;
                      &lt;argument&gt;--port=4848&lt;/argument&gt;
                      &lt;argument&gt;--user=admin&lt;/argument&gt;
                      &lt;argument&gt;--passwordfile=files/password.txt&lt;/argument&gt;
                      &lt;argument&gt;--interactive=false&lt;/argument&gt;
                      &lt;argument&gt;--echo=true&lt;/argument&gt;
                      &lt;argument&gt;--terse=true&lt;/argument&gt;
                      &lt;argument&gt;add-resources&lt;/argument&gt;
                      &lt;argument&gt;--upload=true&lt;/argument&gt;
                      &lt;argument&gt;files/glassfish-resources.xml&lt;/argument&gt;
                  &lt;/arguments&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
  
      &lt;/plugins&gt;
  &lt;/build&gt;
  &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
      &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
  &lt;/properties&gt;
  </code></pre>
  
  <p><strong>My Web.xml</strong></p>
  <pre><code>    &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;web-app xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot;
      xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd&quot;
      id=&quot;WebApp_ID&quot; version=&quot;3.0&quot;&gt;
      &lt;display-name&gt;workflowmanager&lt;/display-name&gt;
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;index.xhtml&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;Resteasy&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;javax.ws.rs.Application&lt;/param-name&gt;
              &lt;param-value&gt;boundary.ApplicationServlet&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Resteasy&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/api/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;resteasy.wider.request.matching&lt;/param-name&gt;
          &lt;param-value&gt;true&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;context-param&gt;
      &lt;param-name&gt;resteasy.servlet.mapping.prefix&lt;/param-name&gt;
      &lt;param-value&gt;/api&lt;/param-value&gt;
      &lt;/context-param&gt;
  &lt;/web-app&gt;
  </code></pre>
  <p><strong>My Beans.xml</strong> (Placed under scr/main/webapp/WEB-INF)</p>
  <pre><code>    &lt;?xml version=&quot;1.0&quot;?&gt;
  &lt;beans bean-discovery-mode=&quot;all&quot;
      xsi:schemaLocation=&quot;http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd&quot;
      xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xmlns=&quot;http://xmlns.jcp.org/xml/ns/javaee&quot;&gt;
  &lt;/beans&gt;
  </code></pre>
  <p><strong>My ApplicationServlet</strong></p>
  <pre><code>    package boundary;
  
  import java.util.HashSet;
  import java.util.Set;
  
  import javax.ws.rs.ApplicationPath;
  import javax.ws.rs.core.Application;
  
  public class ApplicationServlet extends Application{
      
       private Set&lt;Object&gt; singletons = new HashSet&lt;Object&gt;();
          private Set&lt;Class&lt;?&gt;&gt; classes = new HashSet&lt;Class&lt;?&gt;&gt;();
  
          public ApplicationServlet() {
              singletons.add(new UserApi());
          }
  
          @Override
          public Set&lt;Class&lt;?&gt;&gt; getClasses() {
              return classes;
          }
  
          @Override
          public Set&lt;Object&gt; getSingletons() {
              return singletons;
          }
      
  }
  </code></pre>
  <p><strong>My UserApi</strong></p>
  <pre><code>    package boundary;
  
  import java.util.logging.Logger;
  
  import javax.inject.Inject;
  import javax.transaction.Transactional;
  import javax.validation.Valid;
  import javax.ws.rs.BadRequestException;
  import javax.ws.rs.Consumes;
  import javax.ws.rs.DELETE;
  import javax.ws.rs.GET;
  import javax.ws.rs.POST;
  import javax.ws.rs.PUT;
  import javax.ws.rs.Path;
  import javax.ws.rs.PathParam;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.Context;
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.Response;
  import javax.ws.rs.core.UriInfo;
  
  import control.UserService;
  import entity.User;
  
  @Path(&quot;user&quot;)
  @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
  public class UserApi{
      
      @Inject
      UserService userService;
  
      // Create a Logger
      private final static Logger LOGGER = Logger.getLogger(UserApi.class.getName());
  
      /*
       * Will be called by a Rest-Client. This userApi then redirects the call from the client to the userService.
       * After Processing the call this userApi will then respond to the client.
       * 
       * Example Path to make a call: http://localhost:8080/workflowmanager/api/user/
       */
  
      /**
       * API method to post an user
       *
       * @param user
       * @return {@link Response} containing the status of the request and (in case of
       *         success) also the requested contract information
       * @throws Exception
       */
      @Transactional(rollbackOn = Exception.class)
      @POST
      @Consumes(MediaType.APPLICATION_JSON)
      public Response postUser(@Context final UriInfo uriInfo, @Valid final User user) throws Exception {
  
          // create User
          LOGGER.info(String.format(&quot;Try to post User %s&quot;, user.getUsername()));
          final User createdUser = userService.createUser(user);
          LOGGER.info(String.format(&quot;User %s successfully created&quot;, createdUser.getUsername()));
  
          return Response.created(null).build();
      }
  
      /**
       * API method to update an user
       *
       * @param user
       * @return {@link Response} containing the status of the request and (in case of
       *         success) also the requested contract information
       * @throws Exception
       */
      @Transactional(rollbackOn = Exception.class)
      @PUT
      @Consumes(MediaType.APPLICATION_JSON)
      @Path(&quot;/{username}&quot;)
      public Response putUser(@Context final UriInfo uriInfo, @Valid final User user,
              @PathParam(&quot;username&quot;) final String userName) throws Exception {
  
          // avoid change of username
          if (!userName.equals(user.getUsername())) {
              throw new BadRequestException(&quot;Not allowed to change username!&quot;);
          }
  
          // update User
          final User updatedUser = userService.updateUser(user);
          LOGGER.info(String.format(&quot;User %s successfully updated&quot;, updatedUser.getUsername()));
  
          return Response.ok().build();
      }
  
      /**
       * API method to get an user
       *
       * @param userName
       * @return {@link Response} containing the status of the request and (in case of
       *         success) also the requested contract information
       * @throws Exception
       */
      @GET
      @Consumes(MediaType.APPLICATION_JSON)
      @Path(&quot;/{userName}&quot;)
      public Response getUser(@PathParam(&quot;userName&quot;) final String userName) throws Exception {
          LOGGER.info(String.format(&quot;Looking up User %s&quot;, userName));
          final User user = userService.getUser(userName);
          return Response.ok(user).build();
      }
      
      /**
         * API method to deregister an user
         *
         * @param username
         * @return  {@link Response} containing the status of the request and (in case of
       *         success) also the requested contract information
         * @throws Exception
         */
        @Transactional(rollbackOn =Exception.class)
        @DELETE
        @Consumes(MediaType.APPLICATION_JSON)
        @Path(&quot;/{userName}&quot;)
        public Response deleteUser(@PathParam(&quot;userName&quot;) final String userName) throws Exception {
  
         userService.deleteContract(userName);
          return Response.noContent().build();
        }
  }
  </code></pre>
  <p><strong>My UserService</strong></p>
  <pre><code>package control;
  
  import java.util.List;
  import java.util.logging.Logger;
  
  import javax.ejb.Stateless;
  import javax.persistence.EntityManager;
  import javax.persistence.NoResultException;
  import javax.persistence.PersistenceContext;
  import javax.ws.rs.NotFoundException;
  
  import entity.User;
  
  @Stateless
  public class UserService {
      @PersistenceContext(unitName = &quot;workflowManager&quot;)
      EntityManager entityManager;
  
      // Create a Logger
      private final static Logger LOGGER = Logger.getLogger(UserService.class.getName());
  
      /*
       * Hier werden die Anfragen von der userApi (Boundary) ankommen und die Daten
       * manipuliert. Ebenfalls wird hier mit der Datenbank gesprochen
       */
  
      /**
       * Creates a new User
       * 
       * @param user
       * @throws Exception
       */
      public User createUser(final User user) throws Exception {
  
          // check preconditions
          LOGGER.info(String.format(&quot;Checking if user with name %s already exists &quot;, user.getUsername()));
          if (getUser(user.getUsername()) != null) {
              LOGGER.info(String.format(&quot;User %s already exists! Persisting process aborted.&quot;, user.getUsername()));
              throw new Exception(new InternalError(&quot;Something went wrong during the creation of an user&quot;));
          }
  
          // save
          LOGGER.info(String.format(&quot;Creating user with name &quot;, user.getUsername()));
          this.entityManager.persist(user);
          LOGGER.info(String.format(&quot;User %s successfully persisted&quot;, user.getUsername()));
  
          return user;
      }
  
      /**
       * Updates a given user
       *
       * @param user
       * @throws ElcException
       */
      public User updateUser(final User user) throws Exception {
          User existingUser = null;
          final String userName = user.getUsername();
          if (userName != null) {
              LOGGER.info(String.format(&quot;Searching for User with userName %s before updating&quot;, user.getUsername()));
              existingUser = getUser(userName);
          } else {
              throw new Exception(new InternalError(&quot;Something went wrong during the update of an user&quot;));
          }
          user.setId(existingUser.getId());
          LOGGER.info(String.format(&quot;Merging user with username &quot;, user.getUsername()));
          final User mergedUser = this.entityManager.merge(user);
          LOGGER.info(String.format(&quot;updated username with username %s&quot;, user.getUsername()));
  
          return mergedUser;
  
      }
  
      /**
       * Get all available Users as list
       *
       * @return List&lt;User&gt;
       */
      public List&lt;User&gt; getAllUser() throws Exception {
          LOGGER.info(&quot;Retrieving all User ...&quot;);
          try {
              final List&lt;User&gt; user = this.entityManager.createNamedQuery(User.FIND_ALL, User.class).getResultList();
              return user;
          } catch (Exception e) {
              LOGGER.info(String.format(&quot;Getting all users failed %s&quot;, e.getMessage()));
              return null;
          }
  
      }
  
      /**
       * Gets one user by username
       * 
       * @param username
       * @return
       * @throws Exception
       */
      public User getUser(final String userName) throws Exception {
          // Retrieve contractOwner and check if owner exists.
  
          LOGGER.info(String.format(&quot;try to get user with name %s&quot;, userName));
  
          try {
              // get user
              return this.entityManager.createNamedQuery(User.FIND_BY_USERNAME, User.class)
                      .setParameter(&quot;username&quot;, userName).getSingleResult();
  
          } catch (final NoResultException e) {
              // user not found
              LOGGER.info(String.format(&quot;No user %s found! Error Message: %s&quot;, userName, e.getMessage()));
              throw new NotFoundException();
  
          } catch (final Exception e) {
              LOGGER.info(String.format(&quot;Sorry something went wrong - No user %s found! Error Message: %s&quot;, userName,
                      e.getMessage()));
              throw new Exception(new InternalError(&quot;Something went wrong while retreiving an user&quot;));
          }
  
      }
      
      /**
       * Deletes one user by username
       * 
       * @param username
       * @return
       * @throws Exception
       */
       public void deleteContract(final String userName) throws Exception {
              LOGGER.info(String.format(&quot;Deleting user %s&quot;, userName));
              final User user = getUser(userName);
  
              try {
              // delete from database
              this.entityManager.remove(user);
  
              } catch (final Exception e) {
                  LOGGER.info(String.format(&quot;Sorry something went wrong - user %s could not be deleted! Error Message: %s&quot;, userName,
                          e.getMessage()));
                  throw new Exception(new InternalError(&quot;Sorry something went wrong - user could not be deleted!&quot;));
              }
  
              LOGGER.info(String.format(&quot;User successfully removed.&quot;, user.getUsername()));
            }
  
  }
  </code></pre>
  <p><strong>My User</strong></p>
  <pre><code>    package entity;
  
  import java.io.Serializable;
  import javax.persistence.*;
  import javax.validation.constraints.NotNull;
  import javax.validation.constraints.Size;
  
  /**
   * The persistent class for the &quot;USER&quot; database table.
   * 
   */
  @Entity
  @Table(name = &quot;USER&quot;)
  @NamedQueries({@NamedQuery(name = &quot;User.findAll&quot;, query = &quot;SELECT u FROM User u&quot;), 
  @NamedQuery(name = User.FIND_BY_USERNAME,
  query = &quot;SELECT u FROM User u WHERE u.username = :userName&quot;)})
  public class User implements Serializable {
  
      static final String PREFIX = &quot;workflowManager.entity.User.&quot;;
      public static final String FIND_ALL = PREFIX + &quot;findAll&quot;;
      public static final String FIND_BY_USERNAME = PREFIX + &quot;findByUsername&quot;;
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private long id;
  
      @Column(name = &quot;PASSWORD&quot;)
      @NotNull(message = &quot;password is required&quot;)
      @Size(max = 255, message = &quot;password is too long&quot;)
      private String password;
  
      @Column(name = &quot;ROLE&quot;)
      @NotNull(message = &quot;role is required&quot;)
      @Size(max = 255, message = &quot;role is too long&quot;)
      private String role;
  
      @Column(name = &quot;USERNAME&quot;)
      @NotNull(message = &quot;username is required&quot;)
      @Size(max = 255, message = &quot;username is too long&quot;)
      private String username;
  
      // bi-directional many-to-one association to Coderepotarget
      @OneToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = &quot;CODEREPOTARGET&quot;)
      private Coderepotarget coderepotargetBean;
  
      // bi-directional many-to-one association to Workflowtooltarget
      @OneToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = &quot;WORKFLOWTOOLTARGET&quot;)
      private Workflowtooltarget workflowtooltargetBean;
  
      public User() {
      }
  
      public long getId() {
          return this.id;
      }
  
      public void setId(long id) {
          this.id = id;
      }
  
      public String getPassword() {
          return this.password;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
      public String getRole() {
          return this.role;
      }
  
      public void setRole(String role) {
          this.role = role;
      }
  
      public String getUsername() {
          return this.username;
      }
  
      public void setUsername(String username) {
          this.username = username;
      }
  
      public Coderepotarget getCoderepotargetBean() {
          return this.coderepotargetBean;
      }
  
      public void setCoderepotargetBean(Coderepotarget coderepotargetBean) {
          this.coderepotargetBean = coderepotargetBean;
      }
  
      public Workflowtooltarget getWorkflowtooltargetBean() {
          return this.workflowtooltargetBean;
      }
  
      public void setWorkflowtooltargetBean(Workflowtooltarget workflowtooltargetBean) {
          this.workflowtooltargetBean = workflowtooltargetBean;
      }
  
  }
  </code></pre>
  <p><strong>Some more information:</strong>
  After hours of trying to get the userService doing the work I tried to do all the logic within the UserApi itself. I added the persistance-context to the userApi and instanciated the EntityManager. I got another NPE while I tried to use the EntityManager.</p>
  <p>I deploy the app on glassfish5 using the command <code>mvn clean install</code></p>
  <p>I also tried several other Commands like Maven-&gt;Update Project, mvn clean, project clean and I already restarted Eclipse multiple times etc.</p>
  <p>I use CDI 1.0 and a Dynamic Webmodule 3.0 but when I start the server it tells me (without bigger issues):</p>
  <pre><code>BeforeBeanDiscovery.addAnnotatedType(AnnotatedType&lt;?&gt;) used for class org.glassfish.jersey.ext.cdi1x.servlet.internal.CdiExternalRequestScope is deprecated from CDI 1.1! [..]  
  </code></pre>
  <p>I feel like something really strange is going on there as well?</p>
  <p>For now I'm super confused and frustrated, maybe you guys know what is missing.</p>