title: WebSphere Liberty + Springboot + Hibernate + JNDI
body: <p>I am trying to migrate my small application from Tomcat to WebSphere. In order to do so, I am rebuilding it from scratch addressing major components separately. I am struggling with data access / JNDI on webSphere Liberty. I get </p>
  
  <p>javax.naming.NameNotFoundException: javax.naming.NameNotFoundException: java:comp/env/jdbc/test</p>
  
  <p>SERVER.xml</p>
  
  <pre><code>&lt;featureManager&gt;
  &lt;feature&gt;webProfile-8.0&lt;/feature&gt;
  &lt;feature&gt;localConnector-1.0&lt;/feature&gt;
  &lt;feature&gt;adminCenter-1.0&lt;/feature&gt;
  &lt;feature&gt;javaee-8.0&lt;/feature&gt;
  &lt;feature&gt;jndi-1.0&lt;/feature&gt;
  &lt;feature&gt;concurrent-1.0&lt;/feature&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code> &lt;dataSource id="test" jndiName="jdbc/test" type="javax.sql.DataSource"&gt;
      &lt;jdbcDriver libraryRef="MySQLLib" /&gt;
      &lt;properties databaseName="test" serverName="localhost" portNumber="3306" user="user" password="mypassword" /&gt;
      &lt;jdbcDriver&gt;
        &lt;library id="MySQLLib"&gt;
          &lt;fileset dir="/Library/JDBC/" includes="mysql-connector-java-5.1.14-bin.jar" /&gt;
        &lt;/library&gt;
      &lt;/jdbcDriver&gt;
    &lt;/dataSource&gt;
  </code></pre>
  
  <p>Data config class</p>
  
  <pre><code>@Configuration
  public class DataSourceConfig {
  
  @Resource(lookup = "java:comp/env/jdbc/test", name="java:comp/env/jdbc/test")
  private DataSource dataSource;
  </code></pre>
  
  <p>I have also tried this approach :</p>
  
  <pre><code>@Bean
  public DataSource dataSource() throws NamingException {
      return (DataSource) new JndiTemplate().lookup("java:comp/env/jdbc/test");
  }
  </code></pre>