Home > Software design >  Exception Description: Configuration error. Class [com.microsoft.jdbc.sqlserver.SQLServerDriver] not
Exception Description: Configuration error. Class [com.microsoft.jdbc.sqlserver.SQLServerDriver] not

Time:10-19

My project was working fine until one day it didn't. I get the following error when I try to run the project in my tomcat server. I followed other threads in StackOverflow but none of them worked. I cleaned my repository, installed fresh workspace but none of them worked. Someone please help me identify what suddenly went wrong. My pom.xml is as follows

     <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>sqljdbc4</artifactId>
            <version>4.2</version>
     </dependency>
     <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>eclipselink</artifactId>
            <version>2.7.3</version>
            <exclusions>
                <exclusion>
                    <groupId>org.eclipse.persistence</groupId>
                    <artifactId>javax.persistence</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.eclipse.persistence</groupId>
                    <artifactId>jakarta.persistence</artifactId>
                </exclusion>
            </exclusions>
            <!-- <version>2.6.4</version> -->
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>javax.persistence</artifactId>
            <version>2.1.1</version>
        </dependency>

The stack trace is as below

[EL Info]: 2022-10-19 10:48:17.06--ServerSession(1180572281)--Thread(Thread[main,5,main])--EclipseLink, version: Eclipse Persistence Services - 2.7.3.v20180807-4be1041
[EL Severe]: ejb: 2022-10-19 10:48:17.077--ServerSession(1180572281)--Thread(Thread[main,5,main])--Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.7.3.v20180807-4be1041): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error.  Class [com.microsoft.jdbc.sqlserver.SQLServerDriver] not found.
Oct 19, 2022 10:48:17 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class [com.abb.se.ppc.core.boot.SpringContextListener]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ClientContext' defined in URL [file:C:/CapDes_Stage/Code/HE_STAGE/CapDes_G_Config_DB/frame_work_config/frame_work/ui/cap_des_ui.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.abb.se.ppc.client.ClientContext]: Constructor threw exception; nested exception is javax.persistence.PersistenceException: Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.7.3.v20180807-4be1041): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error.  Class [com.microsoft.jdbc.sqlserver.SQLServerDriver] not found.
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1076)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1021)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    ....................
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4768)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5230)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:263)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:432)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:927)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:772)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:345)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:476)

CodePudding user response:

I look at your problem Class [com.microsoft.jdbc.sqlserver.SQLServerDriver] not found mean that it is missing from your classpath. My guess is that you load this class with set String "com.microsoft.jdbc.sqlserver.SQLServerDriver" somewhere in your application. You can check maybe in the file from your stacktrace: cap_des_ui.xml

Please try to change that string "com.microsoft.jdbc.sqlserver.SQLServerDriver" with "com.microsoft.sqlserver.jdbc.SQLServerDriver"

I see that in your pom.xml file you have sqljdbc4 with version 4.2. Also scope (<scope>) for that dependency is not set. More about dependency scopes here: https://blogs.oracle.com/developers/post/mastering-maven-dependency-basics

By default if you do not provide scope it will be compile. This mean that at compile time the artifact with the classes should be added inside your war file. If you want you can unzip your war file and search if really is there.

After some research I found this answer: https://stackoverflow.com/a/32415105/6068297 Credits to user: tanpham for this answer

This answer claim that there is difference in the path name of the class between the two version of the sqljdbc4.

I read it like: sqljdbc4 with version 4.2 (I can't find artifact sqljdbc4.2 in Maven repository):

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

For sqljdbc4 version below 4.2:

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

By the way if this is the problem it will also explain why before it work and now not. You/your team simply updated the dependency sqljdbc4 in the pom file.

Best of luck to all!

  • Related