Spring Boot Unable to load class: com.microsoft.sqlserver.jdbc.SQLServerDriver - java

I've created a new Spring Boot project. I'm trying to setup a DataSource to use MSSQL. However I seem to be getting the error "Unable to load class: com.microsoft.sqlserver.jdbc.SQLServerDriver"
I've placed the file jdbcsql4.jar in a folder in my project /lib/jdbcsq4.jar
In my pom.xml file I've added the following:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
<scope>system</scope>
<optional>true</optional>
<systemPath>${basedir}/lib/sqljdbc4.jar</systemPath>
</dependency>
I have an application.properties file, and I'm defining the database credentials like this:
secondary.datasource.url = jdbc:sqlserver://1.1.1.1:50109
secondary.datasource.username = sa
secondary.datasource.password = mypassword
secondary.datasource.driver-class-name = com.microsoft.sqlserver.jdbc.SQLServerDriver
Can anyone possibly indicate where I may be going wrong?

I managed to solve this issue by following the instructions in this link http://claude.betancourt.us/add-microsoft-sql-jdbc-driver-to-maven/
EDIT:
The original link above no longer exists, but here's a similar link.
http://biercoff.com/add-microsoft-sql-jdbc-driver-to-maven/

For the ppl who facing these issue.
Add dependency in POM.
Microsoft finally made the driver available on the Maven Central Repository.
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
you can check here.
Microsoft link

Related

How to set up IRIS database with Quarkus

I'm trying to use Intersystems IRIS Database with
Quarkus, but I'm getting problems making it work
does anyone knows how to set up the Intersystems IRIS Database
on Quarkus ?
I did that on my pom.xml and also I added the jar
hibernate-iris-1.0.0.jar and intersystems-jdbc-3.2.0.jar but it's not working
<dependency>
<groupId>com.intersystems</groupId>
<artifactId>intersystems-jdbc</artifactId>
<version>3.2.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/intersystems-jdbc-3.2.0.jar</systemPath>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-iris</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/hibernate-iris-1.0.0.jar</systemPath>
</dependency>
This is my application.properties
quarkus:
datasource:
db-kind: other
username: _system
password: *****
jdbc:
url: jdbc:IRIS://localhost:1972/USER
driver: com.intersystems.jdbc.IRISDriver
hibernate-orm:
dialect: org.hibernate.dialect.InterSystemsIRISDialect
jdbc:
timezone: UTC
I found the solution, to set up Intersystems IRIS on Quarkus you need to add manually the jar file, and also you need to set up the pom.xml also some setup from Intersystems was made as a java class. you can see the solution looking at my project on GitHub
this is the link: https://github.com/JoseAdemar/quarkus-project-with-intersystems-ris-database

How to set the variable instrumentationKey for azure monitoring in a spring boot application

I have a issue to setup azure monitoring in spring boot project.
i have the error at each start:
instrumentationKey must be set to report metrics to Azure Monitor.
i have set the application.properties with the following properties:
azure.application-insights.instrumentation-key=VALID-UUID
spring.application.name=test
the dependency of the project looks like:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-spring-boot-metrics-starter</artifactId>
<version>2.1.4</version>
</dependency>
As per this https://learn.microsoft.com/en-us/azure/azure-monitor/app/micrometer-java#using-spring-2x documentation you need to add application-insights-springboot-starter as well.
Otherwise, you can set key as azuremonitor.instrumentationKey. My recommendation would be to add application-insights-springboot-starter along with azure-spring-boot-metrics-starter
Tracing by dependency
azure-spring-boot-metrics-starterazure-spring-boot-metrics-starter -->
micrometer-registry-azure-monitor -->
com.microsoft.azure:applicationinsights-core
Your error message come from AzureMonitorConfig
So I think the key be modify to
azuremonitor.instrumentationKey

The import org.mybatis.dynamic cannot be resolved

I want to try the example of dynamic update statement on this tutorial link : http://www.mybatis.org/mybatis-dynamic-sql/docs/update.html. I saw that it needs the import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider; , So i've searched for dependency in the maven central and added below dependency on my pom.xml
<!-- https://mvnrepository.com/artifact/org.mybatis.dynamic-sql/mybatis-dynamic-sql -->
<dependency>
<groupId>org.mybatis.dynamic-sql</groupId>
<artifactId>mybatis-dynamic-sql</artifactId>
<version>1.0.0</version>
</dependency>
Already tried mvn clean install -U on maven build but still The import org.mybatis.dynamic cannot be resolved error always shows. Where can i have the correct maven dependency for this. Or you can suggest me other dynamic update statement approach on mybatis using xml mapper.
I also added the newest version of it and everything worked as expected. I had the problem, that mybatis-spring-boot-starter did not include mybatis-dynamic-sql.
<dependency>
<groupId>org.mybatis.dynamic-sql</groupId>
<artifactId>mybatis-dynamic-sql</artifactId>
<version>1.3.1</version>
</dependency>

Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]

Below is the dependency in pom.xml:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
<scope>system</scope>
<systemPath>/home/martyn/eclipse-workspace/Jars/ojdbc7-12.1.0.2.jar</systemPath>
</dependency>
The file definitely exists at that location. And in eclipse > Java Resources > Maven dependencies, I can see ojdbc7.12.1.0.2 is listed there.
Also, I'd preferably load this dependency from the repo, like so:
<!-- https://mvnrepository.com/artifact/com.oracle/ojdbc7 -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
</dependency>
...but I get this red x error: Missing artifact com.oracle:ojdbc7:jar:12.1.0.2 So, for now, I'm just putting the local JAR path in the pom.xml.
By the way, here's the Java code in Spring MVC:
#Bean
public DataSource getDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("oracle.jdbc.driver.OracleDriver");
dataSource.setUrl("jdbc:oracle:thin:#localhost:1521:xe");
dataSource.setUsername("budget_admin");
dataSource.setPassword("s3cret");
return dataSource;
}
I know this code works as I have it running OK on my work Windows PC. I'm just trying to setup my home dev. Also, I can successfully sign in on SQL Developer using these credentials.
Any ideas why this driver cannot be loaded?

hibernate-entitymanager NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V

I'm deploying an EAR application built with Maven which has the following dependency in one of the modules:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.1.0.Final</version>
</dependency>
When I try to deploy the application in a Glassfish Server 4.1 I get the following error:
Fatal: java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V
at org.hibernate.internal.NamedQueryRepository.checkNamedQueries(NamedQueryRepository.java:149)
I made some research to solve this problem and made the following attempts:
First Attempt
I found this question and used the script in this article to clean the Glassfish's osgi-cache, as suggested in the question and in this issue of the Glassfish/Payara Github repository. Restarted the server. Same error.
Second Attempt
I found this question and tried the suggestion of the first answer, like this: looking at the dependency tree, I see that hibernate-entitymanager has the following dependency:
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>3.3.0.Final</version>
<scope>compile</scope>
</dependency>
So I searched at my Server installation and found the jboss-logging.jar. The installed version was 3.1.0-GA (I'm not sure right now, but surely it was a previous version of the dependency). I downloaded jboss-logging-3.3.0.Final.jar from the Maven Central Repository and replaced the one in my Server installation. Restarted the server. Same error.
Third Attempt
Some comments in the previous post (and others) suggested to add a property org.jboss.logging.provider=slf4j as I'm using these dependencies for logging:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.21</version>
<scope>test</scope>
</dependency>
I found some .properties files in the /glassfish/domains/domain1/config/ folder but none of them contains such a property and I don't know in which file to add that property. I also made some search in the Admin Console but I didn't found where to add properties. The only logging configuration I found was to configure logging levels.
After that I found where to put some JVM options for the Glassfish Server in the Admin Console and added -Dorg.jboss.logging.provider=slf4j as an option but did not work for me (even more, I had to reboot my computer to get Glassfish in ground zero)
Fourth Attempt
Before all this I had a problem and made another question in StackOverflow. Guided by this comment in that post I changed the project configuration but nothing happened (I solved that problem with a little change in my dependencies, answer still pending)
After all the attempts, I'm running out of ideas and the problem remains. I don't know what could be the problem. Any guide, help or answer will be really appreciated. If anybody needs more details about the situation just let me know.
Thanks in advance for your collaboration.
EDIT 1
I was searching and found this article which says something similar to what I did and adds a provided dependency for jboss-logging like this:
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>3.3.0.Final</version>
<scope>provided</scope>
</dependency>
But the error remains. Apparently it's something with the Server but I can't figure out what. I'm using GlassFish Server Open Source Edition 4.1 (build 13)
I was using JBoss server 7.1 to deploy my project. In my case this error was due to the fact that the I was using jboss-logging-3.3.0.Final.jar in my project but the JBoss 7 had a jboss-logging-3.1.0.GA.jar (/opt/jboss-as-7.1.1.Final/modules/org/jboss/logging/main/) by default. So, may be this was due to the jar conflict or method was not present in the jboss-logging-3.1.0.GA.jar, I am not sure. But replacing the jboss-logging-3.1.0.GA.jar with jboss-logging-3.3.0.Final.jar and change mapping in module.xml (at the same above mentioned location) as follows
<module xmlns="urn:jboss:module:1.1" name="org.jboss.logging">
<resources>
<resource-root path="jboss-logging-3.3.0.Final.jar"/>
<!-- Insert resources here -->
</resources>
<dependencies>
<module name="org.jboss.logmanager"/>
</dependencies>
</module>
And the error was gone. Hope it helps.
This is because GlassFish ships with an earlier version of JBoss Logging and this is being picked up by your application hence the NoSuchMethod error. The version of JBoss Logging shipped with GlassFish 4.1 does not have the method defined. You can try and replace the version of jboss-logging in the modules directory of glassfish this may or may not work but it looks like you tried and failed with this approach.
Another option is to upgrade to the latest Payara 4.1.1.162 which ships with JBoss Logging 3.3.0.Final.
Block Glassfish for using its own lib when project lib is provided
Just create a glassfish-web.xml file in the WEB-INF directory. The contents of the file are shown below:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
 <class-loader delegate="false"/>
</glassfish-web-app>
This ensures that glassfish does not load it's internal libraries, but libraries from your project.

Categories

Resources