配置不同配置的bean列表

yh2wf1be  于 2021-07-23  发布在  Java
关注(0)|答案(0)|浏览(100)

我有一个springboot数据清理应用程序,我们为许多不同的公司使用。我已经建立了一个清理模块库,我们的团队可以根据需要为特定客户机配置这些模块。我想扩展我已经建立的,但我不能让它工作。
总结一下这个问题,我想我正在尝试创建一个bean列表,每个bean的配置都不同,其中可能有同一类的多个示例。
下面是所需配置的示例(使用application.yml):

app.dataEnrichmentSteps:
  - name: Module1 #used to derive name of the Class that has the functionality
    filters:
      - name: FieldIsNotBlank #used to derive name of "filter" classname
        field: someRecordFieldName
      - name: FieldIsBlank
        field: someOtherRecordFieldName
    config:
      mod1cfg-a: someVal
      mod1cfg-b: someVal
  - name: Module2
    filters:
      - name: FieldIsNotBlank #used to derive name of "filter" classname
        field: someRecordFieldName
    config:
      mod2cfg-a: someVal
      mod2cfg-b: someVal
  - name: Module1 #this instance of Module1 has different config, and needs to run after the previous 2
    config:
      mod1cfg-a: someOtherVal
      mod2cfg-b: someOtherValAgain
  - name: Module3
    config:
      mod3cfg-a: hopefully you get the point

该应用程序需要足够灵活,以允许任何模块,在任何顺序,任何次数。目前,在应用程序启动时,我有一个 @Bean 它拉入步骤并构建服务的示例(基于名称)并传入配置。下面是spring为我填充的配置类(我不喜欢,但这是我能做的全部):

@Data
@Component
@ConfigurationProperties(prefix="app")
public class ModuleConfig {
    private List<EnrichmentConfig> dataEnrichmentSteps;

    @Data
    public static class EnrichmentConfig{
        //what kind of Enrichment are we doing?
        private String name;

        //how is the enrichment service configured?
        private HashMap<String, String> config; 

        //on which fields should the enrichment execute on?
        private List<HashMap<String,String>> filters; 
    }
}

我正在与这种配置的动态特性作斗争。理想情况下,如果每个模块都能为其配置定义一个pojo,而不是我使用maps,我会非常喜欢它,但是我遇到的每件事都建议使用一个固定的配置结构,而不是我认为需要灵活的配置结构。
我熟悉 @JsonTypeInfo 以及 @JsonSubTypes 在使用jackson和json负载时,可能会有一些动态结构化的json,但是我似乎不知道如何为spring配置做类似的事情。

暂无答案!

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

相关问题