尝试访问Bean时空指针

时间:2018-04-25 01:04:43

标签: spring dependency-injection javabeans spring-bean

我有一个创建多个bean的配置类:

@Configuration
public class TopLevelConfig {
    @Bean
    public MyMapper myMapper() {
        MyMapper mapper = new MyMapper();
        mapper.registerModule(new MetadataModule());
        return new MyMapper();
    }
}

现在在MetadataModule中:

@Override
public void setupModule(final SetupContext setupContext) {
    final SimpleDeserializers deserializers = new SimpleDeserializers();

    deserializers.addDeserializer(Payload.class, new PayloadDeserializer());
    setupContext.addDeserializers(deserializers);
}

PayloadDeserializer中,我无法自动装配MyMapper课程。我认为这是因为当创建PayloadDeserializer的新对象时,MyMapper的bean还没有被创建。如何允许PayloadDeserializer访问bean对象?

1 个答案:

答案 0 :(得分:1)

您正在通过调用<xcdg:Column.CellContentTemplate> <DataTemplate> <TextBlock Text="{xcdg:CellEditorBinding Converter={StaticResource YourConverter}}" /> </DataTemplate> </xcdg:Column.CellContentTemplate> 自行创建history对象,这就是为什么npm install history没有注入它的原因。要注入/自动工作,你的bean应该是spring管理的。为此,您可以在PayloadDeserializer课程之上使用new PayloadDeserializer(),如下所示。

MyMapper