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
2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -281,17 +281,22 @@ public String toString() {
281
281
}
282
282
283
283
Method findSetter (Class <?> type ) {
284
- return extracted ("set" , type );
284
+ return extracted ("set" , type , true );
285
285
}
286
286
287
287
Method findGetter (Class <?> type ) {
288
- return extracted ("get" , type );
288
+ return extracted ("get" , type , false );
289
289
}
290
290
291
- private Method extracted (String prefix , Class <?> type ) {
291
+ private Method extracted (String prefix , Class <?> type , boolean hasParameter ) {
292
292
for (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
+ }
295
300
if (method != null ) {
296
301
return method ;
297
302
}
Original file line number Diff line number Diff line change @@ -331,6 +331,19 @@ void buildWhenDerivedFromExistingDatabaseWithTypeChange() {
331
331
assertThat (built .getUrl ()).isEqualTo ("jdbc:postgresql://localhost:5432/postgres" );
332
332
}
333
333
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
+
334
347
final class HidePackagesClassLoader extends URLClassLoader {
335
348
336
349
private final String [] hiddenPackages ;
You can’t perform that action at this time.
0 commit comments