如何将 spring Java dsl 配置导入 XML 配置?
How to import spring Java dsl config into XML configuration?
我无法将 java dsl 配置导入 XML 配置。
@Configuration
@EnableIntegration
@IntegrationComponentScan
public class JavaApplicationContext {
@MessagingGateway
public interface helloService {
@Gateway(requestChannel = "requestChnl")
public String sayHello(String msg);
}
@Bean
public IntegrationFlow helloIntFlow() {
return IntegrationFlows.from("requestChnl")
.transform(new GenericTransformer<String, String>() {
@Override
public String transform(String source) {
// TODO Auto-generated method stub
return "Hello "+source;
}})
.get();
}
}
在 XML 配置中,我有 <bean id="hellGtwy" class="com.example.JavaApplicationContext" />
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'helloIntFlow' defined in
com.example.JavaApplicationContext: Initialization of bean failed;
nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'org.springframe
work.integration.config.SplitterFactoryBean#6': FactoryBean threw
exception on object creation; nested exception is
java.lang.IllegalArgumentException: An AbstractReplyPr
oducingMessageHandler may only be referenced once (MY_SPLITTER_ID) -
use scope="prototype"
我无法将异常与我的代码联系起来。我在 java dsl 配置中没有分离器。
实际上 Spring 团队的建议是通过 @ImportResource
.
将 XML 配置注入 Java 和注解配置
从另一方面来说,MY_SPLITTER_ID
也与 Spring 集成 Java DSL 无关。甚至可以使用 XML 配置。
尝试使用 <component-scan>
而不是原始的 <bean>
,如果您想将注释配置与 XML 一起使用。
我无法将 java dsl 配置导入 XML 配置。
@Configuration
@EnableIntegration
@IntegrationComponentScan
public class JavaApplicationContext {
@MessagingGateway
public interface helloService {
@Gateway(requestChannel = "requestChnl")
public String sayHello(String msg);
}
@Bean
public IntegrationFlow helloIntFlow() {
return IntegrationFlows.from("requestChnl")
.transform(new GenericTransformer<String, String>() {
@Override
public String transform(String source) {
// TODO Auto-generated method stub
return "Hello "+source;
}})
.get();
}
}
在 XML 配置中,我有 <bean id="hellGtwy" class="com.example.JavaApplicationContext" />
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helloIntFlow' defined in com.example.JavaApplicationContext: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframe work.integration.config.SplitterFactoryBean#6': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: An AbstractReplyPr oducingMessageHandler may only be referenced once (MY_SPLITTER_ID) - use scope="prototype"
我无法将异常与我的代码联系起来。我在 java dsl 配置中没有分离器。
实际上 Spring 团队的建议是通过 @ImportResource
.
从另一方面来说,MY_SPLITTER_ID
也与 Spring 集成 Java DSL 无关。甚至可以使用 XML 配置。
尝试使用 <component-scan>
而不是原始的 <bean>
,如果您想将注释配置与 XML 一起使用。