Following up on configuring the Oracle JDBC drivers and UCP in Java projects, we last saw how to get the job done with Helidon, a straight forward task thanks to its built-in UCP extension. Today we have a look at Micronaut, which also happens to provide a built-in solution.
Micronaut is a JVM-based, full-stack framework for building modular, easily testable microservice and serverless applications. From the makers of the Grails framework, Micronaut builds on top of 15 years of experience, providing a modern approach to building applications. Micronaut applications can be created in a couple of ways, the preferred option these days is to use https://micronaut.io/launch/ to generate a project based on templates. You can also install the Micronaut CLI (I'd recommend using https://sdkman.io/ for that) for generating projects. Both approaches offer you the same options thus pick the one that suits you best.
Now, when selecting features or capabilities with either Micronaut launch or the CLI make sure to pick jdbc-ucp, as that will add the required configuration to your pom.xml (if you chose Maven) or build.gradle (if you chose Gradle). If the jdbc-ucp feature were not available you can sill configure it manually, like is shown next. For Maven make sure that this dependency is found in the <dependencies> block
As for Gradle, you must have the following dependency in the dependencies block, like this
Once this step is completed we follow to the next which is configuring the datasource. Here you have a choice depending on the type of data access your application is making use of; if it's JPA or plain JDBC then configure as follows in src/main/resources/application.yml
However, if you chose to use GORM instead you must configure a single datasource in src/main/resources/application.yml
Update the database URL, username, and password to match your own settings. After this step you can consume the datasource as you would normally do.
Now, should you need to use a different version of the Oracle JDBC drivers and/or UCP I'm afraid that you'll have to configure additional dependencies in your build files (as shown in the first post) due to the fact that micronaut-jdbc-ucp does not expose the Oracle version as a property like Helidon does for Maven. In Gradle there's no such feature for overriding versions via properties like there is in Maven thus you always have to specify an explicit dependency in the build when overriding a dependency.
Photo by Orlando