I am trying to run simple spring boot application with spring data and r2dbc but when i run select query it does return any record.
Configuration
@Configuration
@EnableR2dbcRepositories("com.ns.repository")
public class R2DBCConfiguration extends AbstractR2dbcConfiguration {
@Bean
@Override
public PostgresqlConnectionFactory connectionFactory() {
return new PostgresqlConnectionFactory(PostgresqlConnectionConfiguration
.builder()
.host("localhost")
.database("employee")
.username("postgres")
.password("nssdw")
.port(5432)
.build());
}
@Bean
public DatabaseClient databaseClient(ConnectionFactory connectionFactory) {
return DatabaseClient.builder().connectionFactory(connectionFactory).build();
}
@Bean
R2dbcRepositoryFactory repositoryFactory(DatabaseClient client) {
RelationalMappingContext context = new RelationalMappingContext();
context.afterPropertiesSet();
return new R2dbcRepositoryFactory(client, context, new DefaultReactiveDataAccessStrategy(new PostgresDialect()));
}
}
Controller which is just simple get request I am not even passing the request paramter just hard coding the id as 1 for the name_id
package com.ns.controller;
import com.ns.entities.Name;
import com.ns.repository.NameRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
@RestController
public class EventDrivenController {
@Autowired
private NameRepository repositoryEvent;
@GetMapping(value = "/pools" )
public Mono<Name> getEmployee() {
Mono<Name> mono = repositoryEvent.findById(1);
repositoryEvent.findById(1).doOnEach(System.out::println);
return mono;
}
}
Reactive repository which is simple get by id request
@Repository
public interface NameRepository extends ReactiveCrudRepository<Name,Integer> {
@Query( "SELECT name_id, last_name, first_name FROM name WHERE name_id = $1")
Mono<Name> findById(Integer id);
}
webclient which is just invoking the get call
public void callwebclient() {
WebClient client = WebClient.create("http://localhost:8080");
Mono<Name> nameMono = client.get()
.uri("/pools")
.retrieve()
.bodyToMono(Name.class);
nameMono.subscribe(System.out::println);
}
main class for spring boot
@SpringBootApplication
public class EventDrivenSystemApplication implements CommandLineRunner {
@Autowired
NameRepository nameRepository;
public static void main(String[] args) {
SpringApplication.run(EventDrivenSystemApplication.class, args);
NameWebClient nameWebClient = new NameWebClient();
nameWebClient.callwebclient();
}
}
Main class which is calling webclient . print statment in the webclient does not print anything
@ComponentScan(basePackages ={"com.ns"})
@SpringBootApplication
@EnableR2dbcRepositories
public class EventDrivenSystemApplication {
public static void main(String[] args) {
SpringApplication.run(EventDrivenSystemApplication.class, args);
NameWebClient nameWebClient = new NameWebClient();
nameWebClient.callwebclient();
}
}