无法向springfactoriesloader加载的spring模块添加属性

x6h2sr28  于 2021-07-26  发布在  Java
关注(0)|答案(0)|浏览(234)

我有一个springboot项目,它引导一个从其他jar加载springfactories的进程。

@SpringBootApplication
public class MyApp{
   /**
    * The entry point of application.
    *
    * @param args the input arguments
    */
   public static void main(String[] args) throws InterruptedException {
       final ConfigurableApplicationContext run = SpringApplication.run(MyApp.class, args);
       new FnContext((AnnotationConfigReactiveWebServerApplicationContext) run).bootstrap();
   }

}

myapp项目有自己的application.yaml文件加载一些配置
上下文引导方法:

AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

         // The SpringFactoriesLoader search for function declarations in external jars spring.factories files
        final List<MyFunction> functionService= SpringFactoriesLoader.loadFactories(Function.class, null);
        function.forEach(k -> {
            // and register functionto load additional spring configuration into the context
            context.register(k.getClass());
            LOG.info("function{}", k);
        });
        // The context is then joined to the Spring Boot run context to get Shared configuration.
        context.setParent(runContext);
        // A refresh is necessary to apply registered beans
        context.refresh();

问题是,当我在springfactoriesloader加载的某个模块中添加属性文件时,所有属性都被忽略,它们只从父属性文件(来自myapp项目的properties.yaml)获取属性
有什么建议吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题