title: why use JndiObjectFactoryBean to config JNDI datasource did not work?
body: <p>when I uss  Java-base to config my JNDI. Spring 4.2.5.</p>
  
  <p>But If I use JndiObjectFactoryBean to config.when I want to get the <code>datasource</code>,the object will be null.</p>
  
  <pre><code>@Bean
      public DataSource dataSource(){
          JndiObjectFactoryBean jndiObjectFactoryBean =new JndiObjectFactoryBean();
          jndiObjectFactoryBean.setJndiName("jdbc/SpittrDS");
          jndiObjectFactoryBean.setResourceRef(true);
          jndiObjectFactoryBean.setProxyInterface(DataSource.class);
          return (DataSource) jndiObjectFactoryBean.getObject();  //NULL!!!
      }
  </code></pre>
  
  <p>But if change the method to this,it work well.</p>
  
  <pre><code>@Bean
      public DataSource dataSource(){
          final JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
          dsLookup.setResourceRef(true);
          DataSource dataSource = dsLookup.getDataSource("java:comp/env/jdbc/SpittrDS");
          return dataSource;
      }
  </code></pre>
  
  <p>I do not know where is the problem.</p>
  
  <p>Tomcat 9.0  context.xml</p>
  
  <pre><code>&lt;Context&gt;
  
      &lt;!-- Default set of monitored resources. If one of these changes, the    --&gt;
      &lt;!-- web application will be reloaded.                                   --&gt;
      &lt;WatchedResource&gt;WEB-INF/web.xml&lt;/WatchedResource&gt;
      &lt;WatchedResource&gt;${catalina.base}/conf/web.xml&lt;/WatchedResource&gt;
  
      &lt;!-- Uncomment this to disable session persistence across Tomcat restarts --&gt;
      &lt;!--
      &lt;Manager pathname="" /&gt;
      --&gt;
  
      &lt;Resource name="jdbc/SpittrDS"
        auth="Container"
        type="javax.sql.DataSource"
        driverClassName="com.mysql.jdbc.Driver"
        url="jdbc:mysql://localhost:3306/spittrds"
        username="root"
        password="1"
        maxActive="100"
        maxIdle="20"
        minIdle="5"
        maxWait="10000"/&gt;
  &lt;/Context&gt;
  </code></pre>