0

My environment:

Gradle 4.8

openjdk version "1.8.0_181"

My dirs like :

/src/main/webapp/META-INF/context.xml

And in context.xml, I put a db resource:

<Resource
    name="jdbc/my_db"
    type="javax.sql.DataSource"
    driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/my_db"
/>

in my build.gradle, I use :

apply plugin: 'java'
apply plugin: 'war' 
apply plugin: 'com.bmuschko.tomcat'
/*... some dependencies ... */
tomcat {
    httpPort = 8080
    httpsPort = 8443
    enableSSL = false
    contextPath = '/'
}

In a jsp, I write

<sql:setDataSource dataSource="jdbc/my_db" />

to use it.

Last I use gradle tomcatRun, and I can access some jsps. but can not find db. error is:

Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for jdbc/my_db"

What is my wrong please? And how to fix it please?

BTW: I see the build/libs/gradle.war file, and context.xml in it.

xunitc
  • 207
  • 1
  • 2
  • 10
  • did you add the needed Jdbc driver in your dependencies? `compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.6'` – M.Ricciuti Nov 05 '18 at 12:31
  • @M.Ricciuti Thank you, I put these jars in the dependencies of build.gradle, if I use the tomcat (not embbed), all is right, but I want to run it with gradle to do some test. – xunitc Nov 05 '18 at 12:35
  • hmm, I think I know the wrong. I must put the factor explicit in context.xml, like factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory". I do not know why, but it will be worked. in tomcat (not embbed), do not must put factor explicit. – xunitc Nov 05 '18 at 13:28

0 Answers0