Spring @返回null的Bean

Spring @返回null的Bean,spring,spring-boot,Spring,Spring Boot,在配置类中,我定义了几个@bean。问题是一些bean在被调用时在另一个类中重新调整null。我想了解为什么会发生这种情况 SoapConfig.class @Configuration @ComponentScan(basePackages = {"mk.test.wsdl","mk.test.Porting"}) public Jaxb2Marshaller marshaller(){ Jaxb2Marshaller marshaller = new Jaxb2Marshaller(

在配置类中,我定义了几个@bean。问题是一些bean在被调用时在另一个类中重新调整null。我想了解为什么会发生这种情况

SoapConfig.class

@Configuration
@ComponentScan(basePackages = {"mk.test.wsdl","mk.test.Porting"})
public Jaxb2Marshaller marshaller(){
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setContextPath("mk.softnet.wsdl");
    System.out.println("out:" + marshaller);
    return marshaller;
}

@Bean
public SaajSoapMessageFactory messageFactory() {
    SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory();
    messageFactory.setSoapVersion(SoapVersion.SOAP_12);
    return messageFactory;
}
肥皂杯

private Jaxb2Marshaller marshaller;
在方法上:

System.out.println(marshaller)
//我得到一些值,比如:
marshalar:org.springframework.oxm.jaxb。Jaxb2Marshaller@376c7d7d
(我不知道这是什么意思)

但如果我离开了这个系统<代码>“Keystrefactorybean”或
“messageFactory”
我总是得到null,我需要在SoapClient.class中定义它

只有以下信息表明了某些情况: [org.springframework.ws.soap.security.support.KeystreactoryBean]类型的Bean“KeystreactoryBean”不适合由所有BeanPostProcessor处理(例如:不适合自动代理)


但是从我读到的内容来看,这不是一个错误。

您在类上有@Configuration注释而不是上面的方法吗?我使用下面的代码运行了,它创建了bean

@Configuration
public class SoapConfig {

    @Bean
    public Jaxb2Marshaller marshaller(){
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        marshaller.setContextPath("mk.softnet.wsdl");
        System.out.println("out:" + marshaller);
        return marshaller;
    }

    @Bean
    public SaajSoapMessageFactory messageFactory() {
        SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory();
        messageFactory.setSoapVersion(SoapVersion.SOAP_12);
        return messageFactory;
    }
}
@Configuration
public class SoapConfig {

    @Bean
    public Jaxb2Marshaller marshaller(){
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        marshaller.setContextPath("mk.softnet.wsdl");
        System.out.println("out:" + marshaller);
        return marshaller;
    }

    @Bean
    public SaajSoapMessageFactory messageFactory() {
        SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory();
        messageFactory.setSoapVersion(SoapVersion.SOAP_12);
        return messageFactory;
    }
}