My spring-boot version is 2.3.3.RELEASE. I want use spring.factories to load EnvironmentPostProcessor. In my project, I haven a parent-child classLoader structure. ConfigFileApplicationListener.class is loaded by parent classLoader, and my environmentPostProcessorImpl is in child classloader path. The source code show that ConfigFileApplicationListener use its classloader to load EnvironmentPostProcessor. So,it can not load. SpringBoot ConfigFileApplicationListener#loadPostProcessors can not load EnvironmentPostProcessor in child classLoader With Java SPI,it use ThreadContextClassLoader to load implementation class. Why Spring do not use ThreadContextClassLoader? Or is there any other solutions.

Comment From: snicoll

@ChenKangQiang I don't really understand what you're doing or why the child context is necessary. An application has a designated ClassLoader and loads its resources from it. If you create a child ClassLoader, the app classloader is not supposed to have access to that. These are general principles that are not linked to Spring Boot.

If you want support, you need to share more about your setup in the form of a small sample that shows the issue. You can do so by attaching a zip to this issue or sharing a GitHub repo url. Thanks.

Comment From: ChenKangQiang

@snicoll We design such a structure,be similar to Tomcat,but follow the parental delegation mechanism. SpringBoot ConfigFileApplicationListener#loadPostProcessors can not load EnvironmentPostProcessor in child classLoader

We use a SharedClassLoader to load shared spring class in order to reduce jvm matespace,and FunctionClassLoader to load function. We use different thread to load every function,and every function has own ApplicationContext with different beans. so, every function has its own spring.factories.

Comment From: wilkinsona

SpringApplication loads all ApplicationListeners, including ConfigFileApplicationListener, via spring.factories using its resource loader's class loader. If it has no resource loader, it'll use ClassUtils.getDefaultClassLoader() which is typically the thread context class loader. ConfigFileApplicationListener then uses its own ClassLoader to load EnvironmentPostProcessors. This feels a bit inconsistent to me, although using getClass().getClassLoader() is a common pattern with SpringFactoriesLoader elsewhere in Spring Boot and in other projects including Spring Framework.

For this specific instance, we could make ConfigFileApplicationListener ApplicationContextAware and use the application context's class loader, but that won't help with calls made elsewhere in Spring Boot or by other projects. I think we'll have to discuss this one as a team to figure out what, if anything, we want to do and when we should do it.

Comment From: ChenKangQiang

@wilkinsona Thank you, we look forward to the results of your discussion.