2017-10-23 13 views
0

スプリングブートで私のPostgresデータソースを作成できません。エラーがここに開始されます。java.lang.IllegalStateException:サポートされていないデータソースタイプが見つかりました

at org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder.getType(DataSourceBuilder.java:138) ~[spring-boot-autoconfigure-1.5.7.RELEASE.jar:1.5.7.RELEASE] 

は、最終的にエラー投げ:

Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: No supported DataSource type found 

を私はxml構成とMavenを使って春のアプリを構築してきましたが、春ブーツとのGradleは私にとって新しいものです。私は@Autowireに設定ファイルからデータソースをプルすることに慣れています。いくつかのSOの回答に基づいて、私はデータベースの設定クラスを追加しました:

import javax.sql.DataSource; 

import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; 
import org.springframework.boot.context.properties.ConfigurationProperties; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.context.annotation.Primary; 
import org.springframework.context.annotation.PropertySource; 

@Configuration 
@PropertySource({ "classpath:application.properties" }) 
public class DatabaseConfig { 

    @Bean 
    @Primary 
    @ConfigurationProperties(prefix = "spring.datasource") 
    public DataSource dataSource() { 

     return DataSourceBuilder.create().build(); 

    } 

} 

私は私のJDBC実装にデータソースをautowireしようとしている:

@Component 
public class JDBCRegionNameDAO implements RegionNameDAO { 

    private JdbcTemplate jdbcTemplate; 

    @Autowired 
    public JDBCRegionNameDAO (DataSource dataSource) { 
     this.jdbcTemplate = new JdbcTemplate(dataSource); 
    } 

} 

私application.properties、私は自分をチェックしましたPostgresの資格情報、およびサービスが実行されている保証:

spring.datasource.driver-class-name=org.postgresql.Driver 

spring.datasource.url=jdbc:postgresql://localhost:5432/world_builder 
spring.datasource.platform=postgres 
spring.datasource.username=postgres 
spring.datasource.password=postgres 

私のbuild.gradleを、私が見たものから、私が必要であることを、ここですべてを持っているようですが、エラーが上記スローされます

buildscript { 
    ext { 
     springBootVersion = '1.5.7.RELEASE' 
    } 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
    } 
} 

apply plugin: 'java' 
apply plugin: 'eclipse-wtp' 
apply plugin: 'org.springframework.boot' 
apply plugin: 'war' 

group = 'group.group' 
version = '0.0.1-SNAPSHOT' 
sourceCompatibility = 1.8 

repositories { 
    mavenCentral() 
} 

configurations { 
    providedRuntime 
} 

dependencies { 

    compile('org.springframework.boot:spring-boot-starter-actuator') 
    compile('org.springframework.boot:spring-boot-starter-jdbc') 
    compile('org.springframework.boot:spring-boot-starter-web') 

    compile('org.springframework.boot:spring-boot-starter-thymeleaf') 
    compile('org.springframework.boot:spring-boot-devtools') 

    compile group: 'org.postgresql', name: 'postgresql', version: '42.1.4' 

    runtime('org.postgresql:postgresql')  

    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat') 
    testCompile('org.springframework.boot:spring-boot-starter-test') 
} 

答えて

0

この問題はcompile('org.springframework.boot:spring-boot-starter-jdbc')の依存関係で発生しています。これを次のように変更すると、私の問題が解決されました。jdbcパッケージまたはその依存関係の1つがサポートされていない可能性があります。 「