枚举实现InitializingBean Java

时间:2019-07-09 09:13:23

标签: java spring enums javabeans initializing

我在Spring bean创建中设置了一些枚举属性。喜欢

enum System implements InitializingBean {
    FOO("Foo"),
    BAR("Bar", "Biz");
    private System(String... labels){ ... }
    private ITransformer transformerBean;
    private IProcessor processorBean;

    public static registerTransformerBean(ITransformer transformerBean, Source source) { ... }

    public static registerProcessorBean(IProcessor processorBean, Source source) { ... }

     @Override
     public void afterPropertiesSet() throws Exception {
         for (Source source : Source.values()) {
             Assert.notNull(source.transformerBean, String.format("Transformer Bean can't be null for %s", source.name()));
             Assert.notNull(source.processorBean, String.format("Processor Bean can't be null for %s", source.name()));
         }
     }
}

在配置程序类中

@Bean public FooTransformer fooTransformer() {
    FooTransformer fooTransformer = new FooTransformer( ... );
    Source.registerTransformerBean(fooTransformer, Source.FOO);
    return fooTransformer;
}

但是这里afterPropertiesSet()类中的Source方法没有执行,我的要求是验证后上下文加载,所有枚举都已链接到bean对象。

不确定这是否是我可以采取的方法。感谢您的帮助。

0 个答案:

没有答案