0
嘗試向http出站網關發送請求時收到以下錯誤。得到響應後,我將json負載轉換爲來自其他帖子的對象列表,我已經讀過它可能是服務激活器或變壓器的問題。我仍然試圖處理EIP和SI。Spring Integration java.lang.IllegalArgumentException:發現模糊參數類型
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();
}
}
樣品負載響應
012對象[{"address":{"street":"Molenwerf","housenumber":"20","postalcode":"1541 WR","city":"Koog aan de Zaan","geoLocation":{"lat":"52.457912","lng":"4.799866"}},"distance":0,"type":"ING"}]
我假設'Transformers.fromJson(Atm []。class)'將返回一個Atm數組,我必須將它轉換爲答覆頻道 – androgirl
M-m-m的atms列表。那麼'Transformers.fromJson()'返回什麼?對,'ObjectToJsonTransformer',但不是一個數組。 ObjectToJsonTransformer'返回的內容已經是不同的故事了...... –
刪除'Arrays.asList()'的確有竅門。我需要了解更多關於ObjectToJsonTransformer的信息。使用Java DSL的文章並不多,但我可以找到它。 – androgirl