'Spring boot @Configuration class Conflicts with compiled one in target

I have the following class for configuring SOAP client. JDK 11 - Spring Boot 2.6.3

@Configuration
public class SoapClientConfig {

    @Bean
    public Jaxb2Marshaller marshaller(){
        Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
        jaxb2Marshaller.setContextPath("io.sth.soap");
        return jaxb2Marshaller;
    }

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

    @Bean
    public HttpComponentsMessageSender messageSender() {
        HttpComponentsMessageSender messageSender = new HttpComponentsMessageSender();
        Credentials cr = new UsernamePasswordCredentials("admin", "*****");
        messageSender.setCredentials(cr);
        return messageSender;
    }

    @Bean
    public MySoapClient soapClientConfig(Jaxb2Marshaller jaxb2Marshaller,
                                         WebServiceMessageFactory messageFactory,
                                         HttpComponentsMessageSender messageSender) {
        MySoapClient soapClient = new MySoapClient();
        soapClient.setMessageFactory(messageFactory);
        soapClient.setMarshaller(jaxb2Marshaller);
        soapClient.setUnmarshaller(jaxb2Marshaller);
        soapClient.setMessageSender(messageSender);
        return soapClient;
    }
}

The POJOs are generated from WSDL via maven-jaxb2-plugin with mvn compile

When I run the application I got the following error

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'soapClientConfig', defined in class path resource [io/sth/SoapClientConfig.class], could not be registered. A bean with that name has already been defined in file [/home/sone/IdeaProjects/sth-gateway/target/classes/io/sth/SoapClientConfig.class] and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

it seems the last compiled version and new runtime are in conflict.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source