For the below code, Get and update operation in the repository work fine. But save operation is not persisting the data into the tables. It works fine if I implement the Repository myself. After the replaced it with the interface extending ReactiveCrudRepository, this problem started. Am I missing something?
@SpringBootApplication
public class ReactiveSqlApplication {
public static void main(String[] args) {
SpringApplication.run(ReactiveSqlApplication.class, args);
}
}
@Data
@AllArgsConstructor
@NoArgsConstructor
@Table("store")
class Store {
@Id
private String id;
private String name;
private String description;
}
interface StoreRepository extends ReactiveCrudRepository<Store, String> {
}
@Configuration
@EnableR2dbcRepositories
class R2dbcConfiguration extends AbstractR2dbcConfiguration {
private final ConnectionFactory connectionFactory;
R2dbcConfiguration(ConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
}
@Override
public ConnectionFactory connectionFactory() {
return this.connectionFactory;
}
}
@Configuration
class ConnectionFactoryConfiguration {
@Bean
ConnectionFactory connectionFactory() {
PostgresqlConnectionConfiguration config = PostgresqlConnectionConfiguration.builder()
.host("localhost")
.port(5433)
.database("testdb")
.username("postgres")
.password("root")
.build();
return new PostgresqlConnectionFactory(config);
}
}
The code is tested as below:
@SpringBootTest
@RunWith(SpringRunner.class)
public class StoreRepositoryTest {
@Autowired
private StoreRepository repository;
@Test
public void all() {
Flux<Store> storeFlux = Flux.just(new Store("1", "a1", "a1"), new Store("2", "a2", "a2"))
.flatMap(store -> repository.save(store));
StepVerifier
.create(storeFlux)
.expectNextCount(2)
.verifyComplete();
Flux<Store> all = repository.findAll();
StepVerifier
.create(all)
.expectNextCount(2)
.verifyComplete();
}
}
save()
method – PumpingString
as id type – Pumping