Getting Started with R2DBC ビデオに続いて、データベースとして PostgreSQL を使用する既存の Spring Boot アプリケーションで、一部のリポジトリをリアクティブに変換します。アプリケーションは変換前に動作します。アプリケーションを起動しようとすると、次のエラーが表示されます。
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'albumReactResource' defined in file [/app/classes/com/mycompany/myapp/web/rest/react/AlbumReactResource.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'albumReactRepository' defined in class path resource [com/mycompany/myapp/config/ReactDatabaseConfig.class]: Unsatisfied dependency expressed through method 'albumReactRepository' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'r2dbcRepositoryFactory' defined in class path resource [com/mycompany/myapp/config/ReactDatabaseConfig.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory] from ClassLoader [sun.misc.Launcher$AppClassLoader@4e0e2f2a]
...
gallery-app_1 | Caused by: java.lang.ClassNotFoundException: org.springframework.data.repository.query.QueryMethodEvaluationContextProvider
gallery-app_1 | at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
gallery-app_1 | at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
gallery-app_1 | at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
gallery-app_1 | at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
gallery-app_1 | ... 51 common frames omitted
QueryMethodEvaluationContextProvider クラスがそこにあるはずです。データベース構成は、既存のデータベースと Spring Data 構成と共存できないと思います。
Spring Boot のバージョンは 2.0.5.RELEASE です。関連する依存関係は次のとおりです。
compile "org.springframework.boot:spring-boot-starter-webflux"
compile "org.springframework.data:spring-data-jdbc:1.0.0.r2dbc-SNAPSHOT"
compile "io.r2dbc:r2dbc-postgresql:1.0.0.M5"
ビデオのコードと同じデータベース構成は次のとおりです。
構成 public class ReactDatabaseConfig {
@Bean
PostgresqlConnectionFactory connectionFactory(){
return new PostgresqlConnectionFactory(
PostgresqlConnectionConfiguration.builder()
.host("localhost")
.database("gallery")
.username("postgres")
.password("")
.build()
);
}
@Bean
DatabaseClient databaseClient(ConnectionFactory connectionFactory){
return DatabaseClient.builder()
.connectionFactory(connectionFactory)
.build();
}
@Bean
R2dbcRepositoryFactory r2dbcRepositoryFactory(DatabaseClient client){
RelationalMappingContext context = new RelationalMappingContext();
context.afterPropertiesSet();
return new R2dbcRepositoryFactory(client, context);
}
@Bean
AlbumReactRepository albumReactRepository(R2dbcRepositoryFactory factory){
return factory.getRepository(AlbumReactRepository.class); <-- exceptions occurs
}
...
}
関連する依存関係の情報は次のとおりです。
+--- org.springframework.data:spring-data-jdbc:1.0.0.r2dbc-SNAPSHOT
| +--- org.springframework.data:spring-data-commons:2.1.1.BUILD-SNAPSHOT -> 2.0.10.RELEASE (*)
...
+--- org.springframework.security:spring-security-data -> 5.0.8.RELEASE
| +--- javax.xml.bind:jaxb-api:2.3.0
| +--- org.springframework.data:spring-data-commons:2.0.10.RELEASE (*)
...
| +--- org.springframework.data:spring-data-jpa:2.0.10.RELEASE
| | +--- org.springframework.data:spring-data-commons:2.0.10.RELEASE
この問題を解決するにはどうすればよいですか?