@Resource not injected in CDI managed bean, but works fine in web servlet
<p>I'm trying to read out a lot of first names from my database using JDBC, and it is working fine in my servlet named HelloServlet. I am actually able to respond to a GET request with a bunch of names.</p>

<pre><code>@WebServlet(name = "helloServlet", value = "/hello")
public class HelloServlet extends HttpServlet {
    @Resource(lookup = "java:global/employeesDS")
    DataSource ds;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List&lt;String&gt; list = new ArrayList&lt;&gt;();

        try(Connection connection = ds.getConnection()) {
            Statement statement = connection.createStatement();
            ResultSet result = statement.executeQuery("SELECT first_name FROM employees");

            while(result.next()) {
                list.add(result.getString(1));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        PrintWriter pw = resp.getWriter();
        for(String name : list) {
            pw.write(name + " " );
        }
    }
}
</code></pre>

<p>When I try the same code in a CDI managed bean, then <code>ds</code> remains <code>null</code>, causing <code>NullPointerException</code> trouble:</p>

<pre><code>@Named("dataFetchBean")
@RequestScoped
public class DataFetchBean {
    @Resource(lookup = "java:global/employeesDS")
    DataSource ds;
    List&lt;String&gt; questions;

    public List&lt;String&gt; getQuestions() {
        try(Connection connection = ds.getConnection()) {
            Statement statement = connection.createStatement();
            ResultSet result = statement.executeQuery("SELECT first_name FROM employees");

            while(result.next()) {
                questions.add(result.getString(1));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return questions;
    }
}
</code></pre>

<p>In case that's relevant, this is my web.xml file:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1"&gt;
    &lt;data-source&gt;
        &lt;name&gt;java:global/employeesDS&lt;/name&gt;
        &lt;class-name&gt;com.mysql.jdbc.jdbc2.optional.MysqlDataSource&lt;/class-name&gt;
        &lt;server-name&gt;localhost&lt;/server-name&gt;
        &lt;port-number&gt;3306&lt;/port-number&gt;
        &lt;database-name&gt;employees&lt;/database-name&gt;
        &lt;user&gt;root&lt;/user&gt;
        &lt;password /&gt;
    &lt;/data-source&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;/web-app&gt;
</code></pre>

<p>This is the index.xhtml document in which I'm trying to use the DataFetchBean CDI managed bean:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:c="http://java.sun.com/jsp/jstl/core"&gt;
&lt;h:head&gt;
    &lt;title&gt;Hello, JDBC!&lt;/title&gt;
&lt;/h:head&gt;
&lt;h:body&gt;
    &lt;table&gt;
        &lt;tr&gt;
            &lt;td&gt;First name&lt;/td&gt;
        &lt;/tr&gt;
        &lt;c:forEach items="#{dataFetchBean.questions}" var="question"&gt;
            &lt;tr&gt;
                &lt;td&gt;
                    #{question}
                &lt;/td&gt;
            &lt;/tr&gt;
        &lt;/c:forEach&gt;
    &lt;/table&gt;
&lt;/h:body&gt;
&lt;/html&gt;
</code></pre>

<p>I'm using Wildfly 10.0.10. Thanks in advance!</p>