2017-08-14 7 views
0

私は春のブートの初心者で、簡単な春のブートアプリケーションを作成しようとしています。 マイフォルダ構造は次のとおりです。「javax.sql.DataSource」が見つかりませんでしたので、私の春の起動アプリケーションの起動に失敗しました

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 

マイMain.javaは次のように

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') 
       } 

application.propertiesは次のように

-> Project 

     -> build.gradle 

     -> settings.gradle 

     -> src/main/java 

      -> package 

       -> Main.java 

       -> UserController.java 

       -> UserRespository.java 

      -> dto 

       -> User.java 

     ->src/main/resouces 

       -> application.properties 

私のbuild.gradleがあります -

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); 
     }; 

    } 

アプリケーションを正常にビルドすることができました。私は、アプリケーションを実行すると、私は次のスタックトレースを使用してアプリケーションを起動することができません取得:

 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 with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as 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. To display the auto-configuration report re-run your application with 'debug' enabled. 
    2017-08-14 20:43:03.198 ERROR 27205 --- [   main]   o.s.b.d.LoggingFailureAnalysisReporter : 

    *************************** 
    APPLICATION FAILED TO START 
    *************************** 

    Description: 

    Parameter 0 of constructor in org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration required a bean of type 'javax.sql.Data Source' that could not be 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 any beans 


    Action: 

     Consider revisiting the conditions above or defining a bean of type 'javax.sql.DataSource' in your configuration. 

私は依存関係ツリーをチェックしているとの両方を見つけることでMySQLのコネクタと同様に休止状態にすることができます。 は、その場合には、私はドライバクラスをロードできません取得し、(= {DataSourceAutoConfiguration.class}を除外する)@EnableAutoConfigurationを削除しようとしたことがあり:はcom.mysql.jdbc.Driver

+0

を追加したことを確認してください? –

+0

私はすべての既存の回答を通過しており、試しています。除外を削除しましたが、mysqlのドライバをロードできないのです – Echo

+0

私は問題がドライバの依存関係にあると思います。githubでコードを共有できますか? –

答えて

0

をあなたのMain.javaクラスのパッケージに内部dtoパッケージを移動する必要があり、あなたの場合、それは次のようになりますsrc/main/java/package/dto

したがって、スプリングブートでスキャンすると、エンティティがスキャナに見えるようになります。

あなたはMySQLドライバ依存

あなたはDataSourceAutoConfigurationを除外する理由
<dependency> 
    <groupId>mysql</groupId> 
    <artifactId>mysql-connector-java</artifactId> 
    <version>5.1.6</version> 
</dependency> 
関連する問題