Miha Zoubek
Miha Zoubek

Reputation: 65

@Bean returning null

In configuration Class i have defined few @Beans. Issue is that some beans when called are retuning null in other class. I would like to understand why this is happening.

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;
}
  @Bean
   public KeyStoreFactoryBean keyStoreFactoryBean(){
       KeyStoreFactoryBean keyStoreFactoryBean = new KeyStoreFactoryBean();
       keyStoreFactoryBean.setPassword("test");
       keyStoreFactoryBean.setLocation(new 
       ClassPathResource("test.jks"));

       return  keyStoreFactoryBean;
   }

SoapClinet.class

private Jaxb2Marshaller marshaller;

in method:

System.out.println(marshaller) //i get some value like: marshalar: org.springframework.oxm.jaxb.Jaxb2Marshaller@376c7d7d (which i do not know what it means)

But If I System.out... "keyStoreFactoryBean" or "messageFactory" i always get null, i need to define this in the SoapClient.class

Only info that indicate something is this: Bean 'keyStoreFactoryBean' of type [org.springframework.ws.soap.security.support.KeyStoreFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

But from what I read this is not a error.

Upvotes: 1

Views: 606

Answers (1)

borban
borban

Reputation: 96

Do you have the @Configuration annotation on the class as opposed to the method like above? I ran the with the below code and it created the 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;
    }
}

Upvotes: 1

Related Questions