When I use a custom classloader I find duplicate loading spring.factories

@SpringBootApplication
public class TestApplication {

    public static void main(String[] args){
        URLClassLoader diskClassLoader = new URLClassLoader(urls("/work/lib"), TestApplication.class.getClassLoader());
        SpringApplication app = new SpringApplication(new DefaultResourceLoader(diskClassLoader),TestApplication.class);
        app.run(args);
    }

    private static URL[] urls(String dir){
        File file = new File(dir);
        List<URL> urls = new ArrayList<>();
        File[] files = file.listFiles();
        if(files != null){
            try{
                for (File listFile : files) {
                    if(listFile.isDirectory() || !listFile.getName().endsWith(".jar")){
                        continue;
                    }
                    urls.add(listFile.toURI().toURL());
                }
            }catch (MalformedURLException e){
                //ignore
            }
        }
        return urls.toArray(new URL[0]);
    }

}

Comment From: wilkinsona

Thanks for the proposal but I don't understand the problem that you're trying to solve. SpringFactoriesLoader already includes a per-ClassLoader cache so repeated loading should not occur. Furthermore, there are many places in the codebase where SpringFactoriesLoader is called but you have only changed one of them. This will lead to inconsistent behavior. Can you please explain?