You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/02/10 12:09:25 UTC

[GitHub] [shardingsphere] SirMin commented on a change in pull request #14729: Compatible with spring boot 2.x

SirMin commented on a change in pull request #14729:
URL: https://github.com/apache/shardingsphere/pull/14729#discussion_r803608261



##########
File path: shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/util/PropertyUtil.java
##########
@@ -101,13 +101,45 @@ private static Object v1(final Environment environment, final String prefix, fin
     
     @SneakyThrows(ReflectiveOperationException.class)
     private static Object v2(final Environment environment, final String prefix, final Class<?> targetClass) {
+        String dashedPrefix = toDashedForm(prefix);
         Class<?> binderClass = Class.forName("org.springframework.boot.context.properties.bind.Binder");
         Method getMethod = binderClass.getDeclaredMethod("get", Environment.class);
         Method bindMethod = binderClass.getDeclaredMethod("bind", String.class, Class.class);
         Object binderObject = getMethod.invoke(null, environment);
-        String prefixParam = prefix.endsWith(".") ? prefix.substring(0, prefix.length() - 1) : prefix;
+        String prefixParam = dashedPrefix.endsWith(".") ? dashedPrefix.substring(0, prefix.length() - 1) : dashedPrefix;
         Object bindResultObject = bindMethod.invoke(binderObject, prefixParam, targetClass);
         Method resultGetMethod = bindResultObject.getClass().getDeclaredMethod("get");
         return resultGetMethod.invoke(bindResultObject);
     }
+
+    /**
+     * Return the specified Java Bean property name in dashed form.
+     * @param name the source name
+     * @return the dashed from
+     */
+    public static String toDashedForm(final String name) {

Review comment:
       @zjcnb done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org