Continuing the series on Oracle JDBC integration with other frameworks it's time to have a look at Spring Boot, arguably the most popular choice at the moment for those developers that prefer just a subset of the enterprise Java technologies (JavaEE or JakartaEE depending on the version) or simply something else.
Spring Boot builds on top of the ideas and base blocks provided by the Spring framework. Spring Boot adds a vast amount of configuration options and defaults that let developers build applications quickly and with less configuration as it was needed in the past. This framework provides integration with popular technologies, libraries, and tools. Yet, as of Spring Boot 2.3.0.RELEASE integration between Oracle JDBC/UCP and Spring Boot is minimal as compared with our previous entries (Helidon, Micronaut). Allow me to explain.
The preferred way to create a Spring Boot application is via the Spring Initialzr application available at https://start.spring.io/. You can select the Oracle JDBC Driver as a dependency but it'll pull dependencies with the outdated com.oracle.jdbc groupId; this issue is being looked at by the Spring Boot team, chances are that the correct GAV coordinates will be readily available in the future. Now, regarding UCP integration, it's also not there yet so we'll have to code the integration ourselves for the time being. Again, the Spring Boot team is aware of UCP and may provide an integration for it just like they do for other connection pool libraries.
If you're building with Apache Maven then the following dependencies must be added to your project.
You may use a different starter or additional dependencies if relying on Spring Data, JPA, or other integrations that build on top of JDBC. If you happen to build with Gradle then you require the same dependencies but declared in the following way
Great, the next step is to create a DataSource bean that relies on UCP and the Oracle JDBC driver; we'd also require a configuration entry for said bean so that bean discovery will be able to find it and wire it up where needed. There are many ways to do this but the simplest one is to define the bean and the configuration in the same class. We build on top of what we learned on the first post (Getting Started with UCP) and expand it with Spring Boot goodies such as additional properties and annotations for configuring the bean, as shown next
Feel free to add/remove as many properties as needed by your application. The final step would be to add values for all those configurable properties, you'd typically use the application.properties file but any other properties configure option provided by Spring Boot would also work.
Photo by Larisa Koshkina