Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot: use database config from WildFly's standalone.xml

I'm currently developing an REST app whith Spring boot. For development, I hardcode my database configuration in application.properties. However, this app is going to be deployed on different WildFly servers, each of them defining their DB config (user credentials) in standalone.xml.

As I'm a newbe to Spring/Java, here is my question: How can I use the DB config from standalone for my spring app?

I already did some research. What I got is to define Services with an @PersistenceContext annotated entity manager. But how can I use it without defining new services, just by using plain JpaRepositories?

like image 784
Fabian Avatar asked Apr 18 '26 04:04

Fabian


1 Answers

In Wildfly you will have a datasource configured with at JNDI name.

Instead of configuring url, username and password you have to configure this JNDI name:

spring.datasource.jndi-name=java:jboss/datasources/myGreatDS

That's all.

like image 122
Simon Martinelli Avatar answered Apr 20 '26 18:04

Simon Martinelli