Saturday, 15 March 2014

java - No suitable Driver found in production and not in eclipse -



java - No suitable Driver found in production and not in eclipse -

as many of know exception , i've fixed many times. time, i've spent 2 week search , seek things, required help of high-level people without success.

i've created java website service oriented architecture entity/dao/service/controller... utilize maven2/hibernate/spring (di & aop) , spring mvc. database mysql.

development environment : - windows - mysql 5.6.1 - tomcat 7

production environment : - debian - mysql 5.6.1 - tomcat 7

when deploy app in tomcat7 eclipse => no rpoblem fine when deploy app in production debian environment => no suitable driver found jdbc:mysql://127.0.0.1:3306/synapse

obviously, database ok in production same users development environment(for now, alter when work) total grant options. can connect database , interact with identifiers.

here datasource.xml

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean class="org.springframework.beans.factory.config.propertyplaceholderconfigurer"> <property name="location"> <value>classpath:properties/database.properties</value> </property> </bean> <bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <property name="driverclassname" value="${jdbc.driverclassname}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean> </beans>

and here, database.properties

jdbc.driverclassname=com.mysql.jdbc.driver jdbc.url=jdbc:mysql://127.0.0.1:3306/synapse jdbc.username=user jdbc.password=password

the pom.xml

<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>fr.synapsegaming</groupid> <artifactid>synapse</artifactid> <version>1.0.0</version> <packaging>war</packaging> <name>synapse</name> <description>synapse gaming website , application</description> <build> <plugins> <plugin> <artifactid>maven-compiler-plugin</artifactid> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <artifactid>maven-war-plugin</artifactid> <version>2.3</version> <configuration> <warsourcedirectory>src/main/webapp</warsourcedirectory> <failonmissingwebxml>false</failonmissingwebxml> </configuration> </plugin> </plugins> </build> <dependencies> <!-- junit testing framework --> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>4.8</version> <scope>test</scope> </dependency> <!-- mysql database driver --> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.30</version> </dependency> <!-- spring framework --> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-core</artifactid> <version>3.2.2.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-test</artifactid> <version>3.2.2.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-webmvc</artifactid> <version>3.2.2.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context</artifactid> <version>3.2.2.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context-support</artifactid> <version>3.2.2.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-beans</artifactid> <version>3.2.2.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-expression</artifactid> <version>3.2.2.release</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-hibernate</artifactid> <version>1.2.9</version> </dependency> <!-- hibernate framework --> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-core</artifactid> <version>3.3.1.ga</version> </dependency> <!-- hibernate annotation --> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-annotations</artifactid> <version>3.3.1.ga</version> </dependency> <!-- hibernate library dependecy start --> <dependency> <groupid>dom4j</groupid> <artifactid>dom4j</artifactid> <version>1.6.1</version> </dependency> <dependency> <groupid>commons-logging</groupid> <artifactid>commons-logging</artifactid> <version>1.1.1</version> </dependency> <dependency> <groupid>commons-collections</groupid> <artifactid>commons-collections</artifactid> <version>3.2.1</version> </dependency> <dependency> <groupid>antlr</groupid> <artifactid>antlr</artifactid> <version>2.7.7</version> </dependency> <dependency> <groupid>log4j</groupid> <artifactid>log4j</artifactid> <version>1.2.12</version> </dependency> <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-log4j12</artifactid> <version>1.5.2</version> </dependency> <dependency> <groupid>javassist</groupid> <artifactid>javassist</artifactid> <version>3.12.1.ga</version> </dependency> <!-- hibernate library dependecy end --> <dependency> <groupid>commons-codec</groupid> <artifactid>commons-codec</artifactid> <version>1.8</version> </dependency> <!-- hibernate info validation --> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-validator</artifactid> <version>5.0.1.final</version> </dependency> <!-- hsqldb --> <dependency> <groupid>org.hsqldb</groupid> <artifactid>hsqldb</artifactid> <version>2.0.0</version> </dependency> <!-- servlet --> <dependency> <groupid>javax.servlet</groupid> <artifactid>servlet-api</artifactid> <version>2.5</version> <scope>provided</scope> </dependency> <dependency> <groupid>jstl</groupid> <artifactid>jstl</artifactid> <version>1.2</version> </dependency> <dependency> <groupid>taglibs</groupid> <artifactid>standard</artifactid> <version>1.1.2</version> </dependency> <!-- apache commons fileupload --> <dependency> <groupid>commons-fileupload</groupid> <artifactid>commons-fileupload</artifactid> <version>1.3.1</version> </dependency> <!-- apache commons io --> <dependency> <groupid>commons-io</groupid> <artifactid>commons-io</artifactid> <version>2.4</version> </dependency> <!-- java validation api --> <dependency> <groupid>javax.validation</groupid> <artifactid>validation-api</artifactid> <version>1.1.0.final</version> </dependency> <!-- java mail service api --> <dependency> <groupid>javax.mail</groupid> <artifactid>mail</artifactid> <version>1.4</version> </dependency> </dependencies> </project>

the stack

java.sql.sqlexception: no suitable driver found jdbc:mysql://127.0.0.1:3306/synapse java.sql.drivermanager.getconnection(drivermanager.java:596) java.sql.drivermanager.getconnection(drivermanager.java:187) org.springframework.jdbc.datasource.drivermanagerdatasource.getconnectionfromdrivermanager(drivermanagerdatasource.java:291) org.springframework.jdbc.datasource.drivermanagerdatasource.getconnectionfromdrivermanager(drivermanagerdatasource.java:277) org.springframework.jdbc.datasource.drivermanagerdatasource.getconnectionfromdrivermanager(drivermanagerdatasource.java:259) org.springframework.jdbc.datasource.drivermanagerdatasource.getconnection(drivermanagerdatasource.java:241) org.springframework.orm.hibernate3.localdatasourceconnectionprovider.getconnection(localdatasourceconnectionprovider.java:81) org.hibernate.jdbc.connectionmanager.openconnection(connectionmanager.java:423) org.hibernate.jdbc.connectionmanager.getconnection(connectionmanager.java:144) org.hibernate.jdbc.abstractbatcher.preparequerystatement(abstractbatcher.java:139) org.hibernate.loader.loader.preparequerystatement(loader.java:1547) org.hibernate.loader.loader.doquery(loader.java:673) org.hibernate.loader.loader.doqueryandinitializenonlazycollections(loader.java:236) org.hibernate.loader.loader.dolist(loader.java:2213) org.hibernate.loader.loader.listignorequerycache(loader.java:2104) org.hibernate.loader.loader.list(loader.java:2099) org.hibernate.loader.hql.queryloader.list(queryloader.java:378) org.hibernate.hql.ast.querytranslatorimpl.list(querytranslatorimpl.java:338) org.hibernate.engine.query.hqlqueryplan.performlist(hqlqueryplan.java:172) org.hibernate.impl.sessionimpl.list(sessionimpl.java:1121) org.hibernate.impl.queryimpl.list(queryimpl.java:79) org.hibernate.impl.abstractqueryimpl.uniqueresult(abstractqueryimpl.java:811) fr.synapsegaming.dao.impl.patchdaoimpl.getlastpatch(patchdaoimpl.java:19) fr.synapsegaming.service.impl.patchserviceimpl.getlastpatch(patchserviceimpl.java:20) fr.synapsegaming.controller.impl.homecontrollerimpl.home(homecontrollerimpl.java:54) sun.reflect.nativemethodaccessorimpl.invoke0(native method) sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) java.lang.reflect.method.invoke(method.java:606) org.springframework.web.method.support.invocablehandlermethod.invoke(invocablehandlermethod.java:219) org.springframework.web.method.support.invocablehandlermethod.invokeforrequest(invocablehandlermethod.java:132) org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:104) org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlemethod(requestmappinghandleradapter.java:745) org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:686) org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:80) org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:925) org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:856) org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:936) org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:827) javax.servlet.http.httpservlet.service(httpservlet.java:620) org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:812) javax.servlet.http.httpservlet.service(httpservlet.java:727) org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52)

my production tomcat on bind address : 127.0.0.1 pingable , telnet on 3306 works fine.

this i've tried : - utilize tomcat connection pool (with mysql driver jar in catalina_home/lib) - install libmysql java - set default jdk 1.7 (built-in version) - tried older version of mysql driver - set same war in eclipse , production (works fine on eclipse) - checked tomcat bind adress (127.0.0.1) - checked tomcat default class loader path (catalina_base/lib/*.jar)

last not least, when set standard jsp test page in tomcat's root jdbc connection, works fine in application. looks spring doesn't load driver (class.forname()). ideas ?

i found solution ! , think lastly spring application : framework grows fast.

i used org.springframework.jdbc.datasource.drivermanagerdatasource deprecated.

<bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource">

to prepare it, used org.apache.commons.dbcp.basicdatasource instead

<bean id="datasource" class="org.apache.commons.dbcp.basicdatasource">

here maven dependency

<dependency> <groupid>commons-dbcp</groupid> <artifactid>commons-dbcp</artifactid> <version>1.4</version> </dependency>

enjoy !

java mysql eclipse spring tomcat

No comments:

Post a Comment