Add property for JNDI DataSource lookup

Add `spring.datasource.jndi-name` property to allow a DataSource to be
looked up from JNDI as an alternative to defining a URL connection.

Fixes gh-989
This commit is contained in:
Phillip Webb
2014-08-26 11:33:09 -07:00
parent 8656402ca6
commit a4925dabf7
5 changed files with 91 additions and 0 deletions

View File

@@ -175,6 +175,7 @@ content into your application; rather pick only the properties that you need.
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
spring.datasource.jndi-name # For JNDI lookup (class, url, username & password are ignored when set)
spring.datasource.max-active=100 # Advanced configuration...
spring.datasource.max-idle=8
spring.datasource.min-idle=8

View File

@@ -1272,6 +1272,27 @@ NOTE: For a pooling `DataSource` to be created we need to be able to verify that
`spring.datasource.driverClassName=com.mysql.jdbc.Driver` then that class has to be
loadable.
[[boot-features-connecting-to-a-jndi-datasource]]
==== Connection to a JNDI DataSource
If you are deploying your Spring Boot application to an Application Server you might want
to configure and manage your DataSource using you Application Servers built in features
and access it using JNDI.
The `spring.datasource.jndi-name` property can be used as an alternative to the
`spring.datasource.url`, `spring.datasource.username` and `spring.datasource.password`
properties to access the `DataSource` from a specific JNDI location. For example, the
following section in `application.properties` shows how you can access a JBoss AS defined
`DataSource`:
[source,properties,indent=0]
----
spring.datasource.jndi-name=java:jboss/datasources/customers
----
[[boot-features-using-jdbc-template]]
=== Using JdbcTemplate
Spring's `JdbcTemplate` and `NamedParameterJdbcTemplate` classes are auto-configured and