Skip to Content
author's profile photo Former Member
Former Member

Cannot obtain ObjectFactory for reference javax.sql.DataSource

Hello,

I am using jdbc/DefaultDB as my datasource through spring-cloud-connector. While deploying it on Java Web Tomcat 7, I am getting below errors:

"Cannot obtain ObjectFactory for reference javax.sql.DataSource"

"org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/apache/catalina/loader/WebappClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of sun/misc/Launcher$AppClassLoader) for the method's defining class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type org/slf4j/ILoggerFactory used in the signature

at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:332)

at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:280)

at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:301)

at com.sap.cloud.runtime.kotyo.mail.client.MailObjectFactory.<clinit>(MailObjectFactory.java:40)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:422)

at java.lang.Class.newInstance(Class.java:442)

at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)

Below is the code snippet for datasource lookup:

final JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();

dsLookup.setResourceRef(true);

DataSource dataSource = dsLookup.getDataSource("java:comp/env/jdbc/DefaultDB");

return dataSource;

I have referenced this resource in my web.xml as follow:

<resource-ref>

<res-ref-name>jdbc/DefaultDB</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

</resource-ref>

Can someone please help in identifying the error resolution?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Aug 23, 2016 at 08:21 AM

    Hi,

    It seems that you've packaged SLF4J within your WAR. Remove it and try again.

    Kind regards,
    Svetlin

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.