JDBC dependency for Maven on Spring mvc - maven

I am using oracle DB to connect with my java code on below used platform:
STS- 3.8.2
Spring -2.0.0.0 release
Maven
Oracle database XE version.
While running the spring boot app,I am getting error of jdbc driver not found for database connection string.
I tried to resolve the same by adding all related dependency, however none of them showing me valid, and also it is unable to download required jar during maven build.
I have also tried manually placing the jars in ./m2 directory by downloading from open source, but still not working.

Below is the maven dependency of Oracle-connector. Oracle connector is
missing so it is giving this error.
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.3.0</version>
</dependency>

Related

Plugin .url=jdbc:oracle:thin or one of its dependencies could not be resolved - Spring Boot liquibase

I'm currently working in my company developing an API in Spring Boot with an Oracle database, the problem is that we use liquibase to create the database, and when I try to use the command:
mvn liquibase:update -Dliquibase.url="jdbc:oracle:thin:#..." -Dliquibase.username="xxx" -Dliquibase.password="xxx" -Dinterface-user="xxx" -Dtablespace-tablas="xxx" -Dtablespace-indices="xxx" -Dstorage-tablas="xxx" -Dstorage-indices="xxx"
It returns me this error:
Plugin .url=jdbc:oracle:thin or one of its dependencies could not be resolved: Failure to find .url=jdbc:oracle:jar:thin in https://maven.oracle
.com was cached in the local repository, resolution will not be reattempted until the update interval of maven.oracle.com has elapsed or updates are for
ced -> [Help 1]
I think it is related with the dependency ojdbc8 from oracle but I can't figure out how to make it work.
I know that all the credentials for the database and everything are correct as I can totally use them to connect to the database with a db manager.
Here is my dependency in pom.xml:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3</version>
</dependency>
Right now I've tried these things:
Downloading the dependency from maven repo (https://mvnrepository.com/artifact/com.oracle.ojdbc/ojdbc8/19.3.0.0) and installing it locally using the command: mvn install:install-file -Dfile=./ojdbc8.jar -DgroupId=com.oracle -DartifactId=ojdbc8 -Dversion=19.3 -Dpackaging=jar.
This supposedly installed the dependency locally, but still does not work.
Adding the oracle server to the dependency repos in maven config, following this oracle guide
(https://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9016)
With this second change I manage to get a different error:
Plugin .url=jdbc:oracle:thin or one of its dependencies could not be resolved: Could not find artifact .url=jdbc:oracle:jar:thin in maven.oracle
.com (https://maven.oracle.com) -> [Help 1]
Could you help me find what am I doing wrong or something that I might be missing? Thanks!
You need to use the follow GAV for downloading the JDBC driver from central maven. Refer to Maven guide for more details
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3.0.0</version>
</dependency>
In the end, the main problem was that I was using the embedded console of IntelliJ and It wasn't working that way, I switched to cmd and it worked...

Invalid web-app-versionType after Spring Upgrade

To support JUnit 5, I recently upgraded a Spring Boot application to version 2.4.7.
Local development uses an embedded Tomcat server, while all other environments run on a Weblogic server 12.1.3.
Everything runs locally, but using the Weblogic Server results in the following exception:
Caused By: weblogic.descriptor.DescriptorException: VALIDATION PROBLEMS WERE FOUND
/weblogic.utils.classloaders.GenericClassLoader#700d06bb finder: weblogic.utils.classloaders.CodeGenClassFinder#40ce7cdd annotation: APP#/WEB-INF/lib/tomcat-embed-websocket-9.0.46.jar!/META-INF/web-fragment.xml:18:3:18:3: problem: cvc-enumeration-valid: string value '4.0' is not a valid enumeration value for web-app-versionType in namespace http://xmlns.jcp.org/xml/ns/javaee
at weblogic.descriptor.internal.MarshallerFactory$1.evaluateResults(MarshallerFactory.java:249)
Other questions on the topic led me to check web.xml, but it contains version="3.0".
I don't know how to proceed because I don't understand where this comes from.
Do you have this in your pom.xml to exclude packaging of the tomcat jar files when creating the war file?
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
The spring-boot-starter-tomcat dependencies must have provided scope.

How to make Oracle JDBC connection and execute queries in Spring Boot?

I didn't get a clear picture on making a Oracle JDBC connection in Spring Boot and executing the queries. Can someone please help me or guide me regarding this issue?
First at all you will need the oracle jdbc driver as maven/gradle dependency. Oracle does not have its driver in the public repository. So you need to download the jdbc driver from oracle and install this jar into a maven dependency.
mvn install:install-file -Dfile=ojdbc7.jar -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.1 -Dpackaging=jar
Or you can go to the oracle specific maven repository and get the stuff from there.
After that you are able to add this dependency to your pom.xml of your application.
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.1</version>
</dependency>
On the https://start.spring.io/ website you can create a brand new application. For the start I would choose Web and JPA.
Now in the application.properties file you can set your jdbc configurations:
spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:yourUrl
spring.datasource.username=username
spring.datasource.password=password
After that you should be able to start and run the application.
For more you should read docs for Springs repositories, custom queries, custom entity manager

Weblogic 12.2.1 + Java 8 + Spring Data JPA + Hibernate 5.x Deployment conflict

I am trying to deploy an EAR file using WebLogic 12.2.1 with Hibernate 5.x and Spring-data-jpa 1.9.4. The same configuration deployed fine on Weblogic 12.1.3. JPA 2.1 is used on both of them.
Weblogic is throwing a ClassNotFoundException and looking for the QueryDsl library which is optional with spring-data:
weblogic.management.DeploymentException: java.lang.ClassNotFoundException: com.mysema.query.types.path.PathBuilder
The manifest for Spring-data even references this jar as optional. Since Oracle publishes none of their source I can't exactly debug the problem .. it seems to throw an error long before my ApplicationContext actually initializes any of the Spring wiring.
The same configuration deploys fine on Websphere 8.5.5. There seems to be some kind of deployment conflict with using Weblogic 12.2.1 but I can't spot any other meaningful differences. Is anyone experiencing something similar?
I managed to overcome this error by explicitly adding querydsl-core and querydsl-jpa to my poms.
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-core</artifactId>
</dependency>

Application tests can connect to and query database but Maven can't load driver

Spring MVC app has Oracle and Hibernate properties in a file like this (persistence-oracle.properties):
# jdbc.X
jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.url=[Database URL]
jdbc.user=[Username]
jdbc.pass=[Password]
# hibernate.X
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
hibernate.show_sql=true
#hibernate.hbm2ddl.auto=create-drop
And while the tests show that the app can connect to and query the database and get data back, when I try to package it with maven, I get this error:
Cannot load JDBC driver class 'oracle.jdbc.driver.OracleDriver'
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
The reason the properties are in this properties file and not hibernate.cfg.xml is because configuration is done via Spring Java Configuration similar to step 3 here
Why can't Maven find the driver while Spring can?
Edit1: Oracle dependency
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
Do you have to mention the oracle driver in the build path? if so, I think it could be the license issue see here Find Oracle JDBC driver in Maven repository
The ojdbc6 dependency what you are looking in the mvnrepo is not exact. One should add the collection tag for ojdbc6 verison dependency to get the jars dumped into your path.

Resources