You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "zhaojinchao95 (via GitHub)" <gi...@apache.org> on 2023/05/22 09:26:01 UTC

[GitHub] [shardingsphere] zhaojinchao95 commented on a diff in pull request #25809: Fix the JDBCRepositorySQL fails to load when using a Fat Jar. (#25784)

zhaojinchao95 commented on code in PR #25809:
URL: https://github.com/apache/shardingsphere/pull/25809#discussion_r1200244235


##########
mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/sql/JDBCRepositorySQLLoader.java:
##########
@@ -57,49 +67,54 @@ public final class JDBCRepositorySQLLoader {
      */
     @SneakyThrows({JAXBException.class, IOException.class, URISyntaxException.class})
     public static JDBCRepositorySQL load(final String type) {
-        File file = new File(JDBCRepositorySQLLoader.class.getProtectionDomain().getCodeSource().getLocation().getPath());
-        return file.isFile() ? loadFromJar(file, type) : loadFromDirectory(type);
-    }
-    
-    private static JDBCRepositorySQL loadFromDirectory(final String type) throws URISyntaxException, IOException {
-        Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(ROOT_DIRECTORY);
-        if (null == urls) {
+        Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources(ROOT_DIRECTORY);
+        if (null == resources) {
             return null;
         }
+        JDBCRepositorySQL jdbcRepositorySQL = null;
+        while (resources.hasMoreElements()) {
+            URL resource = resources.nextElement();
+            jdbcRepositorySQL = isJarURL(resource) ? loadFromJar(resource, type) : loadFromDirectory(resource, type);
+            if (null != jdbcRepositorySQL && Objects.equals(jdbcRepositorySQL.isDefault(), false)) {
+                break;
+            }
+        }
+        return jdbcRepositorySQL;

Review Comment:
   Please change `jdbcRepositorySQL`  to `result`.



-- 
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