mysql - Failing to start my spring boot application due to 'javax.sql.DataSource' that could not be found -


i beginner in spring boot , trying write simple spring boot application. folder structure follows:

  -> project         -> build.gradle         -> settings.gradle         -> src/main/java             -> package                 -> main.java                 -> usercontroller.java                 -> userrespository.java             -> dto                 -> user.java         ->src/main/resouces                 -> application.properties 

my build.gradle follows :

    buildscript {             repositories {                           jcenter()                          }     dependencies {            classpath(                   'org.springframework.boot:spring-boot-gradle- plugin:1.5.6.release'                       )           classpath('mysql:mysql-connector-java:5.1.34')                  }            }      apply plugin: 'java'     apply plugin: 'spring-boot'      sourcecompatibility = 1.8     targetcompatibility = 1.8      repositories {               mavencentral()                  }     dependencies {          compile(               'org.springframework.boot:spring-boot-starter-actuator',               'org.springframework.boot:spring-boot-starter-web',               'org.springframework.boot:spring-boot-starter-data-jpa'                        )         compile('mysql:mysql-connector-java')         testcompile('org.springframework.boot:spring-boot-starter-test')                } 

the application.properties follows:

   spring.jpa.hibernate.ddl-auto=create    spring.datasource.url=jdbc:mysql://localhost:3306/user    spring.datasource.username=root    spring.datasource.password=root    spring.datasource.driver-class-name=com.mysql.jdbc.driver    spring.jpa.database-platform=org.hibernate.dialect.mysqldialect      spring.jpa.database=mysql    spring.jpa.show-sql = true 

my main.java follows:-

  import org.springframework.boot.springapplication;   import org.springframework.boot.autoconfigure.enableautoconfiguration;   import org.springframework.boot.autoconfigure.springbootapplication;   import org.springframework.boot.autoconfigure.jdbc.datasourceautoconfiguration;    @springbootapplication   @enableautoconfiguration(exclude={datasourceautoconfiguration.class})    public class main {             public static void main(string[] args) {                    springapplication.run(main.class, args);       };    } 

i able build application. if run application , unable start application following stacktrace:

     2017-08-14 20:43:02.976  warn 27205 --- [           main]  ationconfigembeddedwebapplicationcontext : exception encountered during context  initialization - cancelling refresh attempt: org.springframework.beans.factory.unsatisfieddependencyexception: error creating bean name 'org.springframework.boot.autoconfigure.orm.jpa.hibernatejpaautoconfiguration': unsatisfied dependency expressed through constructor parameter 0; nested exception org.springframework.beans.factory.nosuchbeandefinitionexception: no qualifying bean of type 'javax.sql.datasource' available: expected @ least 1 bean qualifies autowire candidate. dependency annotations: {}    2017-08-14 20:43:02.978  info 27205 --- [           main] o.apache.catalina.core.standardservice   : stopping service [tomcat]    2017-08-14 20:43:03.007  info 27205 --- [           main] utoconfigurationreportlogginginitializer :      error starting applicationcontext. display auto-configuration   report re-run application 'debug' enabled.    2017-08-14 20:43:03.198 error 27205 --- [           main]         o.s.b.d.loggingfailureanalysisreporter   :       ***************************      application failed start     ***************************      description:      parameter 0 of constructor in  org.springframework.boot.autoconfigure.orm.jpa.hibernatejpaautoconfiguration required bean of type 'javax.sql.data source' not found.          - bean method 'datasource' not loaded because @conditionalonproperty (spring.datasource.jndi-name) did not find property 'jndi-name'          - bean method 'datasource' not loaded because @conditionalonbean (types: org.springframework.boot.jta.xadatasourcewrapper; searchstrategy: all) did not find beans        action:         consider revisiting conditions above or defining bean of type 'javax.sql.datasource' in configuration. 

i have checked dependencies tree , can find both hibernate mysql connector in it. have tried removing @enableautoconfiguration(exclude={datasourceautoconfiguration.class}) , in case cannot load driver class: com.mysql.jdbc.driver

you should move dto package inside main.java class package, in case should src/main/java/package/dto

so when spring-boot scans, entity visible scanner.

make sure have added mysql driver dependency

<dependency>     <groupid>mysql</groupid>     <artifactid>mysql-connector-java</artifactid>     <version>5.1.6</version> </dependency> 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -