- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 java DSL 重写以下 xml configured example:
现在我坚持以下配置部分:
<int:gateway id="userGateway" default-request-timeout="5000"
default-reply-timeout="5000"
service-interface="org.springframework.integration.samples.enricher.service.UserService">
<int:method name="findUser" request-channel="findUserEnricherChannel"/>
<int:method name="findUserByUsername" request-channel="findUserByUsernameEnricherChannel"/>
<int:method name="findUserWithUsernameInMap" request-channel="findUserWithMapEnricherChannel"/>
</int:gateway>
我试图找到任何模拟 here 但我还没有找到。
你能帮我找到它吗?
我尝试编写以下代码:
配置:
@Bean
public IntegrationFlow findUserEnricherChannelFlow() {
return IntegrationFlows.from(UserService.class)
.handle(SystemService.class, "findUser") // I have no idea how to map all methods
.get();
}
调用者:
ConfigurableApplicationContext ctx = new SpringApplication(MyApplication.class).run(args);
UserService userService = ctx.getBean(UserService.class);
User user = new User("some_name",null,null);
System.out.println("Main:" + userService.findUser(user));
用户服务:
public interface UserService {
/**
* Retrieves a user based on the provided user. User object is routed to the
* "findUserEnricherChannel" channel.
*/
//@Gateway(requestChannel = "findUserEnricherChannel", replyChannel = )
User findUser(User user);
/**
* Retrieves a user based on the provided user. User object is routed to the
* "findUserByUsernameEnricherChannel" channel.
*/
User findUserByUsername(User user);
/**
* Retrieves a user based on the provided username that is provided as a Map
* entry using the mapkey 'username'. Map object is routed to the
* "findUserWithMapChannel" channel.
*/
Map<String, Object> findUserWithUsernameInMap(Map<String, Object> userdata);
}
系统服务:
public class SystemService {
private static final Log LOGGER = LogFactory.getLog(SystemService.class);
/** Default Constructor. */
public SystemService() {
super();
}
public User findUser(User user) {
LOGGER.info(String.format("Calling method 'findUser' with parameter %s", user));
final User fullUser = new User(user.getUsername(),
"secret",
user.getUsername() + "@springintegration.org");
return fullUser;
}
public User findUserByUsername(String username) {
LOGGER.info(String.format("Calling method 'findUserByUsername' with parameter: %s", username));
return new User(username, "secret", username + "@springintegration.org");
}
}
但在这种情况下,应用程序无法以以下跟踪启动:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-08-29 16:04:54.293 ERROR 7948 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'findUserEnricherChannelFlow' defined in class path resource [enricher/Config.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.dsl.IntegrationFlow]: Factory method 'findUserEnricherChannelFlow' threw exception; nested exception is java.lang.IllegalStateException: Target object of type [class java.lang.Class] has no eligible methods for handling Messages.
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at enricher.MyApplication.main(MyApplication.java:13) ~[classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.dsl.IntegrationFlow]: Factory method 'findUserEnricherChannelFlow' threw exception; nested exception is java.lang.IllegalStateException: Target object of type [class java.lang.Class] has no eligible methods for handling Messages.
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
... 17 common frames omitted
Caused by: java.lang.IllegalStateException: Target object of type [class java.lang.Class] has no eligible methods for handling Messages.
at org.springframework.util.Assert.state(Assert.java:94) ~[spring-core-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.findHandlerMethodsForTarget(MessagingMethodInvokerHelper.java:898) ~[spring-integration-core-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:293) ~[spring-integration-core-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:223) ~[spring-integration-core-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:227) ~[spring-integration-core-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.integration.handler.MethodInvokingMessageProcessor.<init>(MethodInvokingMessageProcessor.java:54) ~[spring-integration-core-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.integration.handler.ServiceActivatingHandler.<init>(ServiceActivatingHandler.java:46) ~[spring-integration-core-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.integration.dsl.IntegrationFlowDefinition.handle(IntegrationFlowDefinition.java:996) ~[spring-integration-core-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.integration.dsl.IntegrationFlowDefinition.handle(IntegrationFlowDefinition.java:979) ~[spring-integration-core-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at enricher.Config.findUserEnricherChannelFlow(Config.java:36) ~[classes/:na]
at enricher.Config$$EnhancerBySpringCGLIB$$f36636fe.CGLIB$findUserEnricherChannelFlow$0(<generated>) ~[classes/:na]
at enricher.Config$$EnhancerBySpringCGLIB$$f36636fe$$FastClassBySpringCGLIB$$ada0b78a.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at enricher.Config$$EnhancerBySpringCGLIB$$f36636fe.findUserEnricherChannelFlow(<generated>) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
... 18 common frames omitted
我提前做了几个步骤,现在我有以下配置:
@Configuration
@EnableIntegration
@IntegrationComponentScan
public class Config {
@Bean
public SystemService systemService() {
return new SystemService();
}
@Bean
public IntegrationFlow findUserEnricherFlow(SystemService systemService) {
return IntegrationFlows.from("findUserEnricherChannel")
.<User>handle((p, h) -> systemService.findUser(p))
.get();
}
@Bean
public IntegrationFlow findUserByUsernameEnricherFlow(SystemService systemService) {
return IntegrationFlows.from("findUserByUsernameEnricherChannel")
.<User>handle((p, h) -> systemService.findUserByUsername(p.getUsername()))
.get();
}
@Bean
public IntegrationFlow findUserWithUsernameInMapFlow(SystemService systemService) {
return IntegrationFlows.from("findUserWithMapEnricherChannel")
.<Map<String, Object>>handle((p, h) -> {
User user = systemService.findUserByUsername((String) p.get("username"));
Map<String, Object> map = new HashMap<>();
map.put("username", user.getUsername());
map.put("email", user.getEmail());
map.put("password", user.getPassword());
return map;
})
.get();
}
}
服务接口(interface):
@MessagingGateway
public interface UserService {
/**
* Retrieves a user based on the provided user. User object is routed to the
* "findUserEnricherChannel" channel.
*/
@Gateway(requestChannel = "findUserEnricherChannel")
User findUser(User user);
/**
* Retrieves a user based on the provided user. User object is routed to the
* "findUserByUsernameEnricherChannel" channel.
*/
@Gateway(requestChannel = "findUserByUsernameEnricherChannel")
User findUserByUsername(User user);
/**
* Retrieves a user based on the provided username that is provided as a Map
* entry using the mapkey 'username'. Map object is routed to the
* "findUserWithMapChannel" channel.
*/
@Gateway(requestChannel = "findUserWithMapEnricherChannel")
Map<String, Object> findUserWithUsernameInMap(Map<String, Object> userdata);
}
和目标服务:
public class SystemService {
private static final Log LOGGER = LogFactory.getLog(SystemService.class);
/** Default Constructor. */
public SystemService() {
super();
}
public User findUser(User user) {
LOGGER.info(String.format("Calling method 'findUser' with parameter %s", user));
final User fullUser = new User(user.getUsername(),
"secret",
user.getUsername() + "@springintegration.org");
return fullUser;
}
public User findUserByUsername(String username) {
LOGGER.info(String.format("Calling method 'findUserByUsername' with parameter: %s", username));
return new User(username, "secret", username + "@springintegration.org");
}
}
主要方法:
public static void main(String[] args) {
ConfigurableApplicationContext ctx = new SpringApplication(MyApplication.class).run(args);
UserService userService = ctx.getBean(UserService.class);
User user = new User("some_name", null, null);
System.out.println("Main:" + userService.findUser(user));
System.out.println("Main:" + userService.findUserByUsername(user));
Map<String, Object> map = new HashMap<>();
map.put("username", "vasya");
System.out.println("Main:" + userService.findUserWithUsernameInMap(map));
}
输出:
2019-08-30 14:09:29.956 INFO 12392 --- [ main] enricher.MyApplication : Started MyApplication in 2.614 seconds (JVM running for 3.826)
2019-08-30 14:09:29.966 INFO 12392 --- [ main] enricher.SystemService : Calling method 'findUser' with parameter User{username='some_name', password='null', email='null'}
Main:User{username='some_name', password='secret', email='some_name@springintegration.org'}
2019-08-30 14:09:29.967 INFO 12392 --- [ main] enricher.SystemService : Calling method 'findUserByUsername' with parameter: some_name
Main:User{username='some_name', password='secret', email='some_name@springintegration.org'}
2019-08-30 14:09:29.967 INFO 12392 --- [ main] enricher.SystemService : Calling method 'findUserByUsername' with parameter: vasya
Main:{password=secret, email=vasya@springintegration.org, username=vasya}
如您所见,一切正常,但我在配置内部进行了转换。我不确定我是否必须这样做,因为 xml 配置没有这样的转换,并且一切都使用内部魔法以某种方式工作。这是正确的方法还是我应该使用一些内部 DSL 魔法进行转换?
最佳答案
该文档适用于旧版本的 DSL for Spring Integration 4.3;从 5.0 版本开始,DSL 被集成到主项目和文档中。该版本中不存在网关功能。
查看 Wiki 页面顶部的横幅
This project has been absorbed by Spring Integration Core starting with version 5.0. Please consult its Reference Manual for the actual documentation. This project is only in a maintenance, bug fixing state.
参见the current documentation - IntegrationFlow as Gateway .
The IntegrationFlow can start from the service interface that provides a GatewayProxyFactoryBean component, as the following example shows:
public interface ControlBusGateway {
void send(String command);
}
...
@Bean
public IntegrationFlow controlBusFlow() {
return IntegrationFlows.from(ControlBusGateway.class)
.controlBus()
.get();
}
该示例应用程序的工作原理相同
public interface RequestGateway {
String echo(String request);
}
....from(RequestGateway.class)
...
编辑
DSL网关目前不支持不同 channel 的多方法网关。您可以使用多种技术...
@SpringBootApplication
@IntegrationComponentScan // finds the messaging gateway
public class So57709118Application {
public static void main(String[] args) {
SpringApplication.run(So57709118Application.class, args);
}
@Bean
public IntegrationFlow flow() {
return IntegrationFlows.from("gatewayChannel")
//.route(...)
.log()
.nullChannel();
}
@Bean
@DependsOn("flow")
public ApplicationRunner runner(Gate gate) {
return args -> {
gate.method1("bar");
gate.method2("bar");
};
}
}
@MessagingGateway(defaultRequestChannel = "gatewayChannel",
defaultHeaders = @GatewayHeader(name = "method", expression = "#gatewayMethod.name"))
interface Gate {
void method1(String foo);
void method2(String foo);
}
或者,您可以在每个方法上设置 requestChannel,而不是使用通用流程
@MessagingGateway(defaultHeaders = @GatewayHeader(name = "method", expression = "#gatewayMethod.name"))
interface Gate {
@Gateway(requestChannel = "foo")
void method1(String foo);
@Gateway(requestChannel = "bar")
void method2(String foo);
}
关于java - <int :gateway xml tag in java DSL in spring - integration? 的模拟是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57709118/
我目前是一群学生的团队负责人,他们正在为一门类(class)的项目工作,该类(class)目前由电气和计算机工程专业的学生组成。我是一名电气工程专业的学生,我还没有开始研究该项目的软件组件。我觉得
我们对 spring-integration 非常满意,除非事情没有按预期工作。然后真的很难找出发生了什么(我们使用的是xml配置)。有人可以将我指向 spring 集成组件背后的 java 组件以便
我需要评估几个积分,我正在使用正常 (0,1) 密度来测试。 在 python 中 import scipy.integrate as integrate import scipy.stats imp
我想保留原始请求的原始有效负载并将其放在 xslt-transformer 或其他操作中。我丢失了它,因为我使用了 xslt-transformer,并且我只需要转换中的一些元素。所以我的场景是: 1
我想知道在 Spring Integration 中使消息不可变的原因是什么。 仅仅是因为多线程环境中的线程安全吗? 表现?当您每次要向现有消息添加某些内容时都必须创建新消息时,您不会受到性能惩罚吗?
我有一个偶尔会返回 503 错误的 http 网关调用。我想配置 retry advice围绕那个调用,但我不想为每个错误都这样做,只是 503s。 我已经配
我们正在使用 Spring Integration 4.2.3 聚合器组件和定义的组超时,并期望组在给定的超时值内超时,同时向组添加消息和发布大小标准不满足。 但我们看到了不同的结果,当我们向服务输入
我需要轮询邮件服务器。由于我的项目已经在 Spring 中,我使用 Spring-Integration 来轮询邮件服务器。我在这方面很成功。但现在我必须轮询多封电子邮件。有人可以告诉我该怎么做吗。
现在,我正在从事的项目已经达到了一个复杂的水平,需要完成多个步骤(实际上,它变得不可思议!)才能生产出完整/可用的产品。不幸的是,我们并不是从Continuos Integration的心态开始的,所
哪些指标表明应该使用企业集成模式框架?另一方面,哪些指标表明应该坚持使用简单的旧代码进行逻辑流? 就我而言,我们将 Spring Integration 应用于映射/处理应用程序,该应用程序从数据库读
我们在 XML 中有以下工作配置,并正在尝试转换为 DSL。不确定它们是否等效,也尝试使用 inboundAdapter。但是,我无法弄清楚如何在那里设置与并发相关的值。有人可以建议他们是否在 DSL
所以我在玩这个: factors :: Integral a => a -> [a] factors n = filter (\d -> n `rem` d == 0) . takeWhile (\d
我是 Spring 集成的新手,正在尝试建模一个流程,其中我通过 HTTP 进行同步请求和响应,但也是交付的同一流程的一部分将响应发送到队列,对其进行后处理,并让一个单独的进程使用该响应。所以从调用流
我有一个 Spring Integration Flow 项目,它公开了一个 Rest 网关,在收到 Rest POST 请求后,它会执行一些小逻辑。基于一些有效负载参数,我想动态激活另一个 Spri
我浏览了 Internet,在 Spring 论坛上发帖,并阅读了几乎全部在线文档,但我无法弄清楚 Spring Integration 是否可以在单个多资源 (JTA) 事务中处理多个消息。这对于我
我正在查看 spring-projects/spring-integration-samples 中的聚合器示例。 https://github.com/spring-projects/spring-
我正在查看 spring-projects/spring-integration-samples 中的聚合器示例。 https://github.com/spring-projects/spring-
我有一个 spring-integration接受 org.w3c.dom.Document 并返回域对象的转换器。这很好。如果缺少元素,我会引发应用程序异常。 但是,我想将该异常放到错误 chann
我显然已经通读了 documentation , 但我无法找到更详细的幕后情况描述。具体来说,有几个行为我很疑惑: 一般设置 import numpy as np from scipy.integra
我正在使用 Spring Integration 使用以下配置从目录中读取文件。但是,我希望在找到任何文件后停止轮询,直到服务不再重新启动为止。有什么方法可以在运行时更改轮询器延迟或在运行时启动/停止
我是一名优秀的程序员,十分优秀!