File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed
spring-boot-project/spring-boot/src
main/java/org/springframework/boot/jdbc
test/java/org/springframework/boot/jdbc Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -281,17 +281,22 @@ public String toString() {
281281}
282282
283283Method findSetter (Class <?> type ) {
284- return extracted ("set" , type );
284+ return extracted ("set" , type , true );
285285}
286286
287287Method findGetter (Class <?> type ) {
288- return extracted ("get" , type );
288+ return extracted ("get" , type , false );
289289}
290290
291- private Method extracted (String prefix , Class <?> type ) {
291+ private Method extracted (String prefix , Class <?> type , boolean hasParameter ) {
292292for (String candidate : this .names ) {
293- Method method = ReflectionUtils .findMethod (type , prefix + StringUtils .capitalize (candidate ),
294- String .class );
293+ Method method ;
294+ if (hasParameter ) {
295+ method = ReflectionUtils .findMethod (type , prefix + StringUtils .capitalize (candidate ), String .class );
296+ }
297+ else {
298+ method = ReflectionUtils .findMethod (type , prefix + StringUtils .capitalize (candidate ));
299+ }
295300if (method != null ) {
296301return method ;
297302}
Original file line number Diff line number Diff line change @@ -331,6 +331,19 @@ void buildWhenDerivedFromExistingDatabaseWithTypeChange() {
331331assertThat (built .getUrl ()).isEqualTo ("jdbc:postgresql://localhost:5432/postgres" );
332332}
333333
334+ @ Test // gh -27295
335+ void buildWhenDerivedFromCustomTypeSpecifiedReturnsDataSource () {
336+ CustomDataSource dataSource = new CustomDataSource ();
337+ dataSource .setUsername ("test" );
338+ dataSource .setPassword ("secret" );
339+ dataSource .setUrl ("jdbc:postgresql://localhost:5432/postgres" );
340+ DataSourceBuilder <?> builder = DataSourceBuilder .derivedFrom (dataSource ).type (SimpleDriverDataSource .class );
341+ SimpleDriverDataSource testSource = (SimpleDriverDataSource ) builder .build ();
342+ assertThat (testSource .getUsername ()).isEqualTo ("test" );
343+ assertThat (testSource .getUrl ()).isEqualTo ("jdbc:postgresql://localhost:5432/postgres" );
344+ assertThat (testSource .getPassword ()).isEqualTo ("secret" );
345+ }
346+
334347final class HidePackagesClassLoader extends URLClassLoader {
335348
336349private final String [] hiddenPackages ;
You can’t perform that action at this time.
0 commit comments