title: Java EE Error: javax.enterprise.inject.UnsatisfiedResolutionException: Api type
body: <p>I'm in the process of building a simple webapp modelled on the MVC architecture. I have a little JSP page with an HTML form. The form data gets forwarded to a servlet which then delegates to the Controller class.</p>
  
  <p>When clicking submit on the form I get a HTTP Status 500 - Error caused by an "UnsatisfiedResolutionException". It seems the container can't find the Controller?</p>
  
  <p>A <code>Context.xml</code> file serves as my Data Source. I'm using apache tomee webprofile 1.7.4.</p>
  
  <p>The error:</p>
  
  <pre><code>type Exception report
  
  message Error instantiating servlet class a1.DispatcherServlet
  
  description The server encountered an internal error that prevented it from fulfilling this request.
  
  exception
  
  javax.servlet.ServletException: Error instantiating servlet class a1.DispatcherServlet
      org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Thread.java:745)
  root cause
  
  javax.enterprise.inject.UnsatisfiedResolutionException: Api type [a1.Controller] is not found with the qualifiers 
  Qualifiers: [@javax.inject.Named(value=customerController)]
  for injection into Field Injection Point, field name :  customerController, Bean Owner : [DispatcherServlet, Name:null, WebBeans Type:DEPENDENT, API Types:[java.io.Serializable,javax.servlet.GenericServlet,java.lang.Object,a1.DispatcherServlet,javax.servlet.Servlet,javax.servlet.http.HttpServlet,javax.servlet.ServletConfig], Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]]
      org.apache.webbeans.util.InjectionExceptionUtil.throwUnsatisfiedResolutionException(InjectionExceptionUtil.java:60)
      org.apache.webbeans.container.InjectionResolver.getInjectionPointBean(InjectionResolver.java:250)
      org.apache.webbeans.inject.AbstractInjectable.inject(AbstractInjectable.java:76)
      org.apache.webbeans.inject.InjectableField.doInjection(InjectableField.java:65)
      org.apache.webbeans.portable.InjectionTargetImpl.injectFields(InjectionTargetImpl.java:208)
      org.apache.webbeans.portable.InjectionTargetImpl.inject(InjectionTargetImpl.java:194)
      org.apache.webbeans.portable.InjectionTargetImpl.inject(InjectionTargetImpl.java:184)
      org.apache.webbeans.component.AbstractOwbBean.create(AbstractOwbBean.java:125)
      org.apache.openejb.core.WebContext.newInstance(WebContext.java:138)
      org.apache.tomee.catalina.JavaeeInstanceManager.newInstance(JavaeeInstanceManager.java:46)
      org.apache.tomee.catalina.JavaeeInstanceManager.newInstance(JavaeeInstanceManager.java:66)
      org.apache.tomee.catalina.JavaeeInstanceManager.newInstance(JavaeeInstanceManager.java:61)
      org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>DispatcherServlet.java:</p>
  
  <pre><code>package a1;
  
  /* Imports */
  
  public class DispatcherServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
      @Inject
      @Named("customerController")
      private Controller customerController;
  
      @Override
      protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
          try {
              String methodName = "addCustomer";
  
              Method method = customerController.getClass().getDeclaredMethod(methodName, HttpServletRequest.class);
              method.setAccessible(true);
              method.invoke(customerController, req);
  
              req.getRequestDispatcher("/success.jsp").forward(req, resp);
          } catch (SecurityException | IllegalArgumentException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
              throw new RuntimeException(e);
          }
      }
  }
  </code></pre>
  
  <p>CustomerController.java:</p>
  
  <pre><code>package a1;
  
  /* Imports */
  
  @Named("customerController")
  public class CustomerController implements Controller {
  
      @EJB
      private CustomerService customerServiceImpl;
  
      private void addCustomer(HttpServletRequest req) {
          long cn1 = Long.parseLong(req.getParameter("form_cust_no"));
          String n = req.getParameter("form_name");
          String s = req.getParameter("form_surname");
  
          try {
              SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
              String formDate = req.getParameter("form_dob");
              java.util.Date dateUtil = sdf.parse(formDate);
              java.sql.Date dateSql = new java.sql.Date(dateUtil.getTime());
              Customer customer = new Customer(cn1, n, s, dateSql);
  
              customerServiceImpl.addCustomer(customer);
          } catch (ParseException e) {
              throw new RuntimeException(e);
          }
      }
  }
  </code></pre>
  
  <p>Web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  
  &lt;web-app 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/web-app_3_0.xsd"
      version="3.0" metadata-complete="true"&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;a1.DispatcherServlet&lt;/servlet-class&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/dispatcher/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;resource-ref&gt;
          &lt;res-ref-name&gt;jdbc/MyDataSource&lt;/res-ref-name&gt;
          &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
          &lt;res-auth&gt;Container&lt;/res-auth&gt;
      &lt;/resource-ref&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>Persistence.xml:</p>
  
  <pre><code>&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1" xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_1.xsd"&gt;
      &lt;persistence-unit name="Ejb1" transaction-type="JTA"&gt;
          &lt;jta-data-source&gt;jdbc/MyDataSource&lt;/jta-data-source&gt;
  
          &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.connection.autocommit" value="false" /&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>Beans.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>Build.xml</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;project name="h6" default="all" basedir="."&gt;
      &lt;description&gt;Homework 6&lt;/description&gt;
  
      &lt;property file="build.properties" /&gt;
  
      &lt;path id="master-classpath"&gt;
          &lt;fileset dir="C:/myprograms/apache-tomee-webprofile-1.7.4/lib" /&gt;
          &lt;pathelement path="/a1/" /&gt;
      &lt;/path&gt;
  
      &lt;target name="clean" description="Clean class files and war files"&gt;
          &lt;delete file="${targetdeploy.dir}${appname}.war" failonerror="false" /&gt;
          &lt;delete file="${server.dir}/${appname}.war" failonerror="false" /&gt;
          &lt;delete dir="${server.dir}/${appname}" failonerror="false" /&gt;
          &lt;delete dir="/${classpath}/" failonerror="false" /&gt;
      &lt;/target&gt;
  
      &lt;target name="compile" depends="clean" description="Compile all files into target"&gt;
          &lt;javac srcdir="./src/main/java" destdir="./${classpath}" includeAntRuntime="false"&gt;
              &lt;classpath refid="master-classpath" /&gt;
          &lt;/javac&gt;
      &lt;/target&gt;
  
      &lt;target name="copy-classes" depends="compile" description="Copy classes from target into webapp"&gt;
          &lt;copy todir="src/main/webapp/WEB-INF/classes/"&gt;
              &lt;fileset dir="${classpath}" includes="**/*.class" /&gt;
              &lt;fileset dir="${classpath}" includes="**/*.xml" /&gt;
          &lt;/copy&gt;
          &lt;copy todir="src/main/webapp/WEB-INF/lib/"&gt;
              &lt;fileset dir="${classpath}" includes="**/*.jar" /&gt;
          &lt;/copy&gt;
      &lt;/target&gt;
  
      &lt;target name="generate-war" depends="copy-classes" description="Generate war file from webapp contents"&gt;
          &lt;war destfile="./${targetdeploy.dir}${appname}.war" webxml="src/main/webapp/WEB-INF/web.xml"&gt;
              &lt;fileset dir="src/main/webapp/"&gt;
                  &lt;include name="**/*.class" /&gt;
                  &lt;include name="**/*.jsp" /&gt;
                  &lt;include name="**/*.css" /&gt;
                  &lt;include name="**/*.html" /&gt;
                  &lt;include name="**/*.txt" /&gt;
                  &lt;include name="**/*.properties" /&gt;
                  &lt;include name="**/*.jar" /&gt;
                  &lt;include name="**/*.xml" /&gt;
              &lt;/fileset&gt;
          &lt;/war&gt;
      &lt;/target&gt;
  
      &lt;target name="deploy-war" depends="generate-war" description="Copy war file into server"&gt;
          &lt;copy todir="${server.dir}/"&gt;
              &lt;fileset dir="${targetdeploy.dir}"&gt;
                  &lt;include name="*.war" /&gt;
              &lt;/fileset&gt;
          &lt;/copy&gt;
      &lt;/target&gt;
  
      &lt;target name="extract-war" depends="deploy-war"&gt;
          &lt;mkdir dir="${server.dir}/${appname}" /&gt;
          &lt;unwar src="${server.dir}/${appname}.war" dest="${server.dir}/${appname}" /&gt;
      &lt;/target&gt;
  
      &lt;target name="all" depends="extract-war" /&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Build.properties:</p>
  
  <pre><code>server.dir=C:/myprograms/apache-tomee-webprofile-1.7.4/webapps
  classpath=target/ide/classes
  targetdeploy.dir=target/deploy/
  appname=h6
  </code></pre>
  
  <p>Folder structure:  </p>
  
  <p><a href="https://i.stack.imgur.com/KPuHL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KPuHL.png" alt="enter image description here"></a></p>