diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilder.java index 8ce8d3d2d2..d1f6e4b47e 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilder.java @@ -24,6 +24,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.jdbc.core.ArgumentPreparedStatementSetter; import org.springframework.jdbc.core.ArgumentTypePreparedStatementSetter; +import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.PreparedStatementSetter; import org.springframework.jdbc.core.RowMapper; import org.springframework.util.Assert; @@ -310,6 +311,20 @@ public JdbcCursorItemReaderBuilder rowMapper(RowMapper rowMapper) { return this; } + /** + * Creates a {@link BeanPropertyRowMapper} to be used as your + * {@link RowMapper}. + * + * @param mappedClass the class for the row mapper + * @return this instance for method chaining + * @see BeanPropertyRowMapper + */ + public JdbcCursorItemReaderBuilder beanRowMapper(Class mappedClass) { + this.rowMapper = new BeanPropertyRowMapper<>(mappedClass); + + return this; + } + /** * Validates configuration and builds a new reader instance. * diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilderTests.java index 3b8b7609f8..e0a6eaf0b6 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilderTests.java @@ -301,15 +301,7 @@ public void testOtherProperties() { .ignoreWarnings(true) .driverSupportsAbsolute(true) .useSharedExtendedConnection(true) - .rowMapper((rs, rowNum) -> { - Foo foo = new Foo(); - - foo.setFirst(rs.getInt("FIRST")); - foo.setSecond(rs.getString("SECOND")); - foo.setThird(rs.getString("THIRD")); - - return foo; - }) + .beanRowMapper(Foo.class) .build(); assertEquals(1, ReflectionTestUtils.getField(reader, "fetchSize"));