Я пытаюсь создать источник данных, как предлагается в некоторых онлайн-примерах Spring, следующим образом:
@Configuration
public class RepositoryConfiguration {
@Primary
@Bean
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
}
У меня есть файл application.yml, который выглядит следующим образом:
spring:
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:54320/mydb
username: postgres
password: somepassword
Когда я запускаю отладчик и оцениваю DataSourceBuilder.create().build();
значения, похоже, не установлены. Любая идея, что может отсутствовать?
![enter image description here](https://i.stack.imgur.com/Wa749.png)
Я использую версию 2.2.4 Spring boot
Это мой build.gradle
файл
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath "org.postgresql:postgresql:42.2.11"
}
}
plugins {
id 'org.springframework.boot' version '2.2.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id 'org.flywaydb.flyway' version '6.3.0'
id 'nu.studer.jooq' version '4.1'
}
group 'com.solution.asclepius'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
annotationProcessor 'org.projectlombok:lombok:1.18.8'
implementation 'org.jooq:jooq'
implementation 'org.jooq:jooq-codegen'
jooqRuntime 'org.postgresql:postgresql:42.2.11'
implementation 'org.projectlombok:lombok:1.18.8'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-jooq'
implementation 'io.vavr:vavr:0.10.2'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.1.0'
testCompile group: 'org.assertj', name: 'assertj-core', version: '3.15.0'
}
jooq {
sample(sourceSets.main) {
jdbc {
driver = 'org.postgresql.Driver'
url = 'jdbc:postgresql://localhost:54320/asclepiusdb'
user = 'postgres'
password = 'somepassword'
}
generator {
database() {
name = 'org.jooq.meta.postgres.PostgresDatabase'
inputSchema = 'public'
includes = '.*'
}
target {
packageName = 'com.solution.asclepius'
directory = 'build/generated/java'
}
}
}
}
tasks.generateSampleJooqSchemaSource.with {
def out = new ByteArrayOutputStream()
javaExecSpec = { JavaExecSpec s ->
s.standardOutput = out
s.errorOutput = out
s.ignoreExitValue = true
s.jvmArgs '-Xmx512M'
}
execResultHandler = { ExecResult r ->
if (r.exitValue != 0) {
throw new RuntimeException('jOOQ source code generation failed:\n\n' + out.toString())
}
}
}
flyway {
url = 'jdbc:postgresql://localhost:54320/asclepiusdb'
user = 'postgres'
password = 'somepassword'
schemas = ['public']
locations = ["filesystem:$project.projectDir/src/main/resources/db/migration"]
}
В данный момент приложение не загружается:
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under 'spring.datasource' to javax.sql.DataSource:
Property: spring.datasource.driver-class-name
Value: org.postgresql.Driver
Origin: class path resource [application.yml]:4:24
Reason: Failed to load driver class org.postgresql.Driver in either of HikariConfig class loader or Thread context classloader
Action:
Update your application's configuration