Spring boot JNDI datasource lookup failure - Name comp/env/jdbc not found in context “java:”

前端 未结 4 1191
北海茫月
北海茫月 2020-12-10 16:28

I have setup a spring boot (v 1.1.9) application to deploy as a WAR file. And I\'m trying to integrate this web application with an existing data service module (added as a

4条回答
  •  长情又很酷
    2020-12-10 16:37

    I am able to connect my Spring-Boot application (deployed in Websphere Application Server 9) to WAS datasource. The following code worked for me, for connecting to DataSource:

    @Bean(name = "WASDataSource")
    public DataSource WASDataSource() throws Exception {        
    JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
    return dataSourceLookup.getDataSource("DSNAME");
    }   
    
    @Bean(name = "WASDataSourceJdbcTemplate")
    public JdbcTemplate jdbcTemplate_WASDS(@Qualifier("WASDataSource")
    DataSource dsDB2) {
    return new JdbcTemplate(dsDB2);
    }
    

    Note: The name of Datasource "DSNAME" is the name which appears on the UI of Websphere console. You can see that via -> Select Resources > JDBC > Data Sources.

    Then I created jdbc template:

    @Autowired
    @Qualifier("WASDataSourceJdbcTemplate")
    private JdbcTemplate db2WASTemplate;`
    

    And running query using the query method works fine :
    db2WASTemplate.query()

    I did not create any Web.xml or ibm-web-bnd.xml files

提交回复
热议问题