简体   繁体   中英

JNDI configuration with spring boot with WebSphere 9.0.0.7

I have added spring.datasource.jndi-name=java:comp/env/jdbc/DB_Name property in application.properties file, datasource not created.

I want to use that datasoure with spring boot 2.0.3, spring boot data jpa(hibernate),websphere. Need to use the jparepository for CURD operations.

I have seen the similar issue . But we don't have web.xml in spring boot to add resource reference. So can't follow that answer. How can I achieve the jparepository.

Need to add the below property in application.properties

spring.datasource.jndi-name=jdbc/yourjndiname

In SpringApplication.java class where is our spring boot main method exist.Below code generates the datasource for us.

@Autowired
    private Environment env;
@Bean
    public DataSource dataSource() throws NamingException {
        return (DataSource) new JndiTemplate().lookup(env.getProperty("spring.datasource.jndi-name"));
    }

And one more thing If you want access to your table in schema level mention the schema name in @Table(schema = "DB_SCHEMA",name = "DB_TABLE")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM