Spring boot @Configuration类与目标中编译的类冲突
我有以下用于配置 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-plugin
和 mvncompile
从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论