I have a Spring Boot app with a spring.datasource.jndi-name=java:/foo
property and it works well under WildFly.
I'd like to run the same app with an embedded container, i.e. mvn spring-boot:run
, but while WildFly has the JNDI datasource configured in its configuration, an embedded container does not i.e. I' getting:
org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException:
Failed to look up JNDI DataSource with name 'java:/foo'
I suppose I have to include an XML file somewhere to configure the JNDI datasource for the embedded container, but I couldn't find documentation about this. I've just found tutorials on how to create the JNDI datasource in the Java source code, but I'd like to avoid this so that same app can run within external and embedded container both.
How can I achieve this?
EDIT This answer shows how to create the JNDI context in Tomcat in a way that would break running the same app in other containers (e.g. WildFly). I'm looking for an answer which lets the app run with the same sources in different containers, e.g. just configuring the embedded container with the same JNDI resources configured in WildFly.