尝试向http出站网关发送请求时收到以下错误。在得到响应之后,我将json有效负载转换为其他帖子中的对象列表,我已经读过它可能是服务激活器或变换器的问题。我仍在尝试处理EIP和SI。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'httpPostAtms' defined in class path resource [com/backbase/atm/config/InfrastructorConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.dsl.IntegrationFlow]: Factory method 'httpPostAtms' threw exception; nested exception is java.lang.IllegalArgumentException: Found ambiguous parameter type [class java.lang.Object] for method match: [public default java.util.stream.Stream java.util.Collection.parallelStream(), public void java.util.Arrays$ArrayList.forEach(java.util.function.Consumer), public void java.util.Arrays$ArrayList.sort(java.util.Comparator), public boolean java.util.AbstractCollection.remove(java.lang.Object), public java.util.ListIterator java.util.AbstractList.listIterator(int), public java.lang.Object[] java.util.Arrays$ArrayList.toArray(java.lang.Object[]), public default boolean java.util.Collection.removeIf(java.util.function.Predicate), public boolean java.util.AbstractCollection.retainAll(java.util.Collection), public void java.util.Arrays$ArrayList.replaceAll(java.util.function.UnaryOperator)]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at com.backbase.atm.IngAtmApplication.main(IngAtmApplication.java:23) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.dsl.IntegrationFlow]: Factory method 'httpPostAtms' threw exception; nested exception is java.lang.IllegalArgumentException: Found ambiguous parameter type [class java.lang.Object] for method match: [public default java.util.stream.Stream java.util.Collection.parallelStream(), public void java.util.Arrays$ArrayList.forEach(java.util.function.Consumer), public void java.util.Arrays$ArrayList.sort(java.util.Comparator), public boolean java.util.AbstractCollection.remove(java.lang.Object), public java.util.ListIterator java.util.AbstractList.listIterator(int), public java.lang.Object[] java.util.Arrays$ArrayList.toArray(java.lang.Object[]), public default boolean java.util.Collection.removeIf(java.util.function.Predicate), public boolean java.util.AbstractCollection.retainAll(java.util.Collection), public void java.util.Arrays$ArrayList.replaceAll(java.util.function.UnaryOperator)]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
... 18 common frames omitted
Caused by: java.lang.IllegalArgumentException: Found ambiguous parameter type [class java.lang.Object] for method match: [public default java.util.stream.Stream java.util.Collection.parallelStream(), public void java.util.Arrays$ArrayList.forEach(java.util.function.Consumer), public void java.util.Arrays$ArrayList.sort(java.util.Comparator), public boolean java.util.AbstractCollection.remove(java.lang.Object), public java.util.ListIterator java.util.AbstractList.listIterator(int), public java.lang.Object[] java.util.Arrays$ArrayList.toArray(java.lang.Object[]), public default boolean java.util.Collection.removeIf(java.util.function.Predicate), public boolean java.util.AbstractCollection.retainAll(java.util.Collection), public void java.util.Arrays$ArrayList.replaceAll(java.util.function.UnaryOperator)]
at org.springframework.util.Assert.isNull(Assert.java:113) ~[spring-core-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.integration.util.MessagingMethodInvokerHelper.findHandlerMethodsForTarget(MessagingMethodInvokerHelper.java:499) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:226) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:149) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:144) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.handler.MethodInvokingMessageProcessor.<init>(MethodInvokingMessageProcessor.java:60) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.transformer.MethodInvokingTransformer.<init>(MethodInvokingTransformer.java:47) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.dsl.IntegrationFlowDefinition.transform(IntegrationFlowDefinition.java:516) ~[spring-integration-java-dsl-1.2.2.RELEASE.jar:na]
at org.springframework.integration.dsl.IntegrationFlowDefinition.transform(IntegrationFlowDefinition.java:496) ~[spring-integration-java-dsl-1.2.2.RELEASE.jar:na]
at org.springframework.integration.dsl.IntegrationFlowDefinition.transform(IntegrationFlowDefinition.java:483) ~[spring-integration-java-dsl-1.2.2.RELEASE.jar:na]
at com.backbase.atm.config.InfrastructorConfig.httpPostAtms(InfrastructorConfig.java:50) ~[classes/:na]
at com.backbase.atm.config.InfrastructorConfig$$EnhancerBySpringCGLIB$$154e5ed2.CGLIB$httpPostAtms$1(<generated>) ~[classes/:na]
at com.backbase.atm.config.InfrastructorConfig$$EnhancerBySpringCGLIB$$154e5ed2$$FastClassBySpringCGLIB$$30080451.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at com.backbase.atm.config.InfrastructorConfig$$EnhancerBySpringCGLIB$$154e5ed2.httpPostAtms(<generated>) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_45]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
... 19 common frames omitted
我的配置
package com.backbase.atm.config;
import java.util.Arrays;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.integration.annotation.IntegrationComponentScan;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.integration.dsl.core.Pollers;
import org.springframework.integration.dsl.http.Http;
import org.springframework.integration.dsl.support.Transformers;
import org.springframework.integration.scheduling.PollerMetadata;
import org.springframework.messaging.MessageChannel;
import com.backbase.atm.model.Atm;
@IntegrationComponentScan
@Configuration
@EnableIntegration
@ComponentScan
public class InfrastructorConfig {
@Bean
public MessageChannel requestChannel() {
return new DirectChannel() ;
}
@Bean(name = PollerMetadata.DEFAULT_POLLER)
public PollerMetadata poller() {
return Pollers.fixedRate(500).get();
}
@Bean
public IntegrationFlow httpPostAtms() {
return IntegrationFlows.from("requestChannel")
.handle(Http.outboundGateway("https://www.ing.nl/api/locator/atms/")
.httpMethod(HttpMethod.GET)
.expectedResponseType(String.class))
.<String, String>transform(p -> p.substring(5))
.transform(Arrays.asList(Transformers.fromJson(Atm[].class)))
.channel("responseChannel")
.get();
}
}
我的网关
package com.backbase.atm.service;
import java.util.List;
import org.springframework.integration.annotation.Gateway;
import org.springframework.integration.annotation.MessagingGateway;
import org.springframework.messaging.handler.annotation.Payload;
import com.backbase.atm.model.Atm;
@MessagingGateway
public interface IntegrationService {
@Gateway(requestChannel = "requestChannel")
@Payload("'string'")
List<Atm> getAllAtms();
}
我试图将有效负载转换为
的对象 package com.backbase.atm.model;
public class Atm {
private Address address;
String distance;
String type;
public Atm() {
super();
}
public Atm(Address address) {
setAddress(address);
}
public Atm(Address address, String distance, String type) {
super();
this.address = address;
this.distance = distance;
this.type = type;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public String getDistance() {
return distance;
}
public void setDistance(String distance) {
this.distance = distance;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Atm: address=").append(address).append(", distance=").append(distance).append(", type=")
.append(type).append("");
return builder.toString();
}
}
样本有效负载响应
[{"address":{"street":"Molenwerf","housenumber":"20","postalcode":"1541 WR","city":"Koog aan de Zaan","geoLocation":{"lat":"52.457912","lng":"4.799866"}},"distance":0,"type":"ING"}]
答案 0 :(得分:0)
您有可疑代码:
.transform(Arrays.asList(Transformers.fromJson(Atm[].class)))
是什么驱使你在那里使用Arrays.asList()
?
您使用的Transformers.fromJson()
只是一个工厂,并为您返回有效的Transformer
对象。 .transform()
可以简单地处理那个。