Spring boot @Configuration类与目标中编译的类冲突

发布于 2025-01-09 04:12:11 字数 2113 浏览 0 评论 0原文

我有以下用于配置 SOAP 客户端的类。 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;
    }
}

POJO 是通过 maven-jaxb2-pluginmvncompile 从 WSDL 生成的

当我运行应用程序时,出现以下错误

***************************
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

,似乎是上次编译的版本和新的运行时存在冲突。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文