2017-02-06 7 views
0

次のバネ統合サンプルをJava Configバージョンに変換しようとしています。Spring IntegrationFlow Http.inboundGatewayのあいまいなパラメータタイプ

本番環境で作業するには、このプロジェクトを少し修正したバージョンが必要です。私の問題は、アプリケーションを起動するときに次の例外が続くことです。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'httpInboundGateway' defined in org.springframework.platform.proxy.TunnelApplication: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.dsl.IntegrationFlow]: Factory method 'httpInboundGateway' threw exception; nested exception is java.lang.IllegalArgumentException: Found ambiguous parameter type [class [Ljava.lang.String;] for method match: [public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.multipartResolver(org.springframework.web.multipart.MultipartResolver), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.replyMapper(org.springframework.integration.mapping.OutboundMessageMapper), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.autoStartup(boolean), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.mappedResponseHeaders(java.lang.String[]), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.phase(int), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.crossOrigin(org.springframework.integration.dsl.support.Consumer), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.errorChannel(java.lang.String), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.headerMapper(org.springframework.integration.mapping.HeaderMapper), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.requestMapper(org.springframework.integration.mapping.InboundMessageMapper), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.messageConverters(org.springframework.http.converter.HttpMessageConverter[]), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.requestTimeout(long), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.payloadExpression(org.springframework.expression.Expression), public java.lang.Class org.springframework.integration.dsl.core.IntegrationComponentSpec.getObjectType(), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.requestPayloadType(java.lang.Class), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.payloadFunction(org.springframework.integration.dsl.support.Function), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.errorChannel(org.springframework.messaging.MessageChannel)] 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE] 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE] 
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE] 
    at org.springframework.platform.proxy.TestServerApplication.main(TestServerApplication.java:11) [classes/:na] 
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.dsl.IntegrationFlow]: Factory method 'httpInboundGateway' threw exception; nested exception is java.lang.IllegalArgumentException: Found ambiguous parameter type [class [Ljava.lang.String;] for method match: [public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.multipartResolver(org.springframework.web.multipart.MultipartResolver), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.replyMapper(org.springframework.integration.mapping.OutboundMessageMapper), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.autoStartup(boolean), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.mappedResponseHeaders(java.lang.String[]), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.phase(int), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.crossOrigin(org.springframework.integration.dsl.support.Consumer), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.errorChannel(java.lang.String), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.headerMapper(org.springframework.integration.mapping.HeaderMapper), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.requestMapper(org.springframework.integration.mapping.InboundMessageMapper), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.messageConverters(org.springframework.http.converter.HttpMessageConverter[]), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.requestTimeout(long), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.payloadExpression(org.springframework.expression.Expression), public java.lang.Class org.springframework.integration.dsl.core.IntegrationComponentSpec.getObjectType(), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.requestPayloadType(java.lang.Class), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.payloadFunction(org.springframework.integration.dsl.support.Function), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.errorChannel(org.springframework.messaging.MessageChannel)] 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    ... 18 common frames omitted 
Caused by: java.lang.IllegalArgumentException: Found ambiguous parameter type [class [Ljava.lang.String;] for method match: [public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.multipartResolver(org.springframework.web.multipart.MultipartResolver), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.replyMapper(org.springframework.integration.mapping.OutboundMessageMapper), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.autoStartup(boolean), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.mappedResponseHeaders(java.lang.String[]), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.phase(int), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.crossOrigin(org.springframework.integration.dsl.support.Consumer), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.errorChannel(java.lang.String), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.headerMapper(org.springframework.integration.mapping.HeaderMapper), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.requestMapper(org.springframework.integration.mapping.InboundMessageMapper), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.messageConverters(org.springframework.http.converter.HttpMessageConverter[]), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.requestTimeout(long), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.payloadExpression(org.springframework.expression.Expression), public java.lang.Class org.springframework.integration.dsl.core.IntegrationComponentSpec.getObjectType(), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.requestPayloadType(java.lang.Class), public org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec org.springframework.integration.dsl.http.BaseHttpInboundEndpointSpec.payloadFunction(org.springframework.integration.dsl.support.Function), public org.springframework.integration.dsl.core.MessagingGatewaySpec org.springframework.integration.dsl.core.MessagingGatewaySpec.errorChannel(org.springframework.messaging.MessageChannel)] 
    at org.springframework.util.Assert.isNull(Assert.java:92) ~[spring-core-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.integration.util.MessagingMethodInvokerHelper.findHandlerMethodsForTarget(MessagingMethodInvokerHelper.java:497) ~[spring-integration-core-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:226) ~[spring-integration-core-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:149) ~[spring-integration-core-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:144) ~[spring-integration-core-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.integration.handler.MethodInvokingMessageProcessor.<init>(MethodInvokingMessageProcessor.java:60) ~[spring-integration-core-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.integration.handler.ServiceActivatingHandler.<init>(ServiceActivatingHandler.java:37) ~[spring-integration-core-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.integration.dsl.IntegrationFlowDefinition.handle(IntegrationFlowDefinition.java:985) ~[spring-integration-java-dsl-1.2.1.RELEASE.jar:na] 
    at org.springframework.integration.dsl.IntegrationFlowDefinition.handle(IntegrationFlowDefinition.java:964) ~[spring-integration-java-dsl-1.2.1.RELEASE.jar:na] 
    at org.springframework.integration.dsl.IntegrationFlowDefinition.handle(IntegrationFlowDefinition.java:950) ~[spring-integration-java-dsl-1.2.1.RELEASE.jar:na] 
    at org.springframework.platform.proxy.TunnelApplication.httpInboundGateway(TunnelApplication.java:93) ~[classes/:na] 
    at org.springframework.platform.proxy.TunnelApplication$$EnhancerBySpringCGLIB$$4e2cc6e6.CGLIB$httpInboundGateway$3(<generated>) ~[classes/:na] 
    at org.springframework.platform.proxy.TunnelApplication$$EnhancerBySpringCGLIB$$4e2cc6e6$$FastClassBySpringCGLIB$$e8c73d4b.invoke(<generated>) ~[classes/:na] 
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.platform.proxy.TunnelApplication$$EnhancerBySpringCGLIB$$4e2cc6e6.httpInboundGateway(<generated>) ~[classes/:na] 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_66] 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_66] 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_66] 
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_66] 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    ... 19 common frames omitted 

ここに私の変更されたバージョンのTunnelApplicationがあります。オリジナルは上記のプロジェクトリンクにあります。

package org.springframework.platform.proxy; 

import org.springframework.amqp.core.*; 
import org.springframework.amqp.rabbit.connection.ConnectionFactory; 
import org.springframework.amqp.rabbit.core.RabbitTemplate; 
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; 
import org.springframework.beans.factory.annotation.*; 
import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 
import org.springframework.boot.web.servlet.ServletRegistrationBean; 
import org.springframework.context.annotation.*; 
import org.springframework.integration.config.EnableIntegration; 
import org.springframework.integration.dsl.*; 
import org.springframework.integration.dsl.amqp.Amqp; 
import org.springframework.integration.dsl.http.Http; 
import org.springframework.web.client.RestTemplate; 
import org.springframework.web.context.support.HttpRequestHandlerServlet; 

@Configuration 
@ComponentScan 
@EnableAutoConfiguration 
@EnableIntegration 
public class TunnelApplication 
{ 
    public static void main(String[] args) 
    { 
     SpringApplication.run(TunnelApplication.class, args); 
    } 

    @Value("${urlExpression}") 
    private String urlExpression; 

    @Value("${outboundQueue}") 
    private String outboundQueue; 

    @Value("${inboundQueue}") 
    private String inboundQueue; 

    @Autowired 
    private ConnectionFactory rabbitConnectionFactory; 

    @Bean 
    public Queue requestQueue() 
    { 
     return new Queue(outboundQueue, true, false, true); 
    } 

    @Bean 
    public Queue targetQueue() 
    { 
     return new Queue(inboundQueue, true, false, true); 
    } 

    @Bean 
    public ServletRegistrationBean httpInboundGatewayServletRegistration() 
    { 
     ServletRegistrationBean bean = new ServletRegistrationBean(httpInboundGatewayServlet(), "/tunnel/*"); 
     bean.setName("httpInboundGateway"); 
     return bean; 
    } 

    @Bean 
    public HttpRequestHandlerServlet httpInboundGatewayServlet() 
    { 
     return new HttpRequestHandlerServlet(); 
    } 

    @Bean 
    public RestTemplate safeRestTemplate() 
    { 
     return new RestTemplate(); 
    } 

    @Bean 
    public Jackson2JsonMessageConverter jsonMessageConverter() 
    { 
     return new Jackson2JsonMessageConverter(); 
    } 


    @Bean 
    public AmqpTemplate amqpTemplate() 
    { 
     RabbitTemplate result = new RabbitTemplate(rabbitConnectionFactory); 
     result.setMessageConverter(jsonMessageConverter()); 
     return result; 
    } 

    @Bean 
    public IntegrationFlow httpInboundGateway() 
    { 
     return IntegrationFlows.from("outbound") 
       .handle(Http.inboundGateway("/tunnel")) 
       .get(); 
    } 

    @Bean 
    public IntegrationFlow amqpOutbound(AmqpTemplate amqpTemplate) 
    { 
     return IntegrationFlows.from("outbound") 
       .handle(
         Amqp.outboundAdapter(amqpTemplate) 
          .mappedRequestHeaders("http_*") 
          .routingKeyExpression("headers['routingKey']") 
         ) 
       .get(); 
    }  

    @Bean 
    public IntegrationFlow amqpInboundGateway(ConnectionFactory connectionFactory) 
    { 
     return IntegrationFlows.from("inbound").handle 
       (
        Amqp.inboundGateway(connectionFactory, inboundQueue) 
         .mappedRequestHeaders("http_*") 
         .messageConverter(jsonMessageConverter()) 
       ) 
       .get(); 
    } 

    @Bean 
    public IntegrationFlow httpOutboundGateway() 
    { 
     return IntegrationFlows.from("inbound").handle(Http.outboundGateway(urlExpression)).get(); 
    } 
} 

私はTunnelApplicationを実行すると上記のエラーが発生します。私のmaven pomファイルは次のように変更されています。主な違いは、私が春のブート1.5.1を使用しているということです。元のプロジェクトは1.1.4.BUILD-SNAPSHOTを使用しています。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <parent> 
     <groupId>com.redi</groupId> 
     <artifactId>redi-parent</artifactId> 
     <version>5.0.0</version> 
    </parent> 
    <artifactId>http-amqp-tunnel</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>HTTP AMQP Tunnel</name> 

    <dependencyManagement> 
     <dependencies> 
      <dependency> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-starter-parent</artifactId> 
       <version>1.5.1.RELEASE</version> 
       <type>pom</type> 
       <scope>import</scope> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-actuator</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-integration</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.integration</groupId> 
      <artifactId>spring-integration-amqp</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.integration</groupId> 
      <artifactId>spring-integration-http</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.integration</groupId> 
      <artifactId>spring-integration-jmx</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <start-class>org.springframework.platform.proxy.TunnelApplication</start-class> 
     <java.version>1.8</java.version> 
    </properties> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

私は本当にいくつかのガイダンスに感謝します。これは私の最初の春の統合プロジェクトで、私は近くにいるように感じます。

ご協力いただきありがとうございます。

改訂設定

package org.springframework.platform.proxy; 

import org.springframework.amqp.core.*; 
import org.springframework.amqp.rabbit.connection.ConnectionFactory; 
import org.springframework.amqp.rabbit.core.RabbitTemplate; 
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; 
import org.springframework.beans.factory.annotation.*; 
import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 
import org.springframework.boot.web.servlet.ServletRegistrationBean; 
import org.springframework.context.annotation.*; 
import org.springframework.integration.config.EnableIntegration; 
import org.springframework.integration.dsl.*; 
import org.springframework.integration.dsl.amqp.Amqp; 
import org.springframework.integration.dsl.http.Http; 
import org.springframework.web.client.RestTemplate; 
import org.springframework.web.context.support.HttpRequestHandlerServlet; 

@Configuration 
@ComponentScan 
@EnableAutoConfiguration 
@EnableIntegration 
public class TunnelApplication 
{ 
    public static void main(String[] args) 
    { 
     SpringApplication.run(TunnelApplication.class, args); 
    } 

    @Value("${urlExpression}") 
    private String urlExpression; 

    @Value("${outboundQueue}") 
    private String outboundQueue; 

    @Value("${inboundQueue}") 
    private String inboundQueue; 

    @Autowired 
    private ConnectionFactory rabbitConnectionFactory; 

    @Bean 
    public Queue requestQueue() 
    { 
     return new Queue(outboundQueue, true, false, true); 
    } 

    @Bean 
    public Queue targetQueue() 
    { 
     return new Queue(inboundQueue, true, false, true); 
    } 

    @Bean 
    public ServletRegistrationBean httpInboundGatewayServletRegistration() 
    { 
     ServletRegistrationBean bean = new ServletRegistrationBean(httpInboundGatewayServlet(), "/tunnel/*"); 
     bean.setName("httpInboundGateway"); 
     return bean; 
    } 

    @Bean 
    public HttpRequestHandlerServlet httpInboundGatewayServlet() 
    { 
     return new HttpRequestHandlerServlet(); 
    } 

    @Bean 
    public RestTemplate safeRestTemplate() 
    { 
     return new RestTemplate(); 
    } 

    @Bean 
    public Jackson2JsonMessageConverter jsonMessageConverter() 
    { 
     return new Jackson2JsonMessageConverter(); 
    } 


    @Bean 
    public AmqpTemplate amqpTemplate() 
    { 
     RabbitTemplate result = new RabbitTemplate(rabbitConnectionFactory); 
     result.setMessageConverter(jsonMessageConverter()); 
     return result; 
    } 

    @Bean 
    public IntegrationFlow httpInboundGateway() 
    { 
     return IntegrationFlows.from(Http.inboundGateway("/tunnel")).channel("outbound") 
       .get(); 
    } 

    @Bean 
    public IntegrationFlow amqpOutbound(AmqpTemplate amqpTemplate) 
    { 
     return IntegrationFlows.from("outbound") 
       .handle(
         Amqp.outboundAdapter(amqpTemplate) 
          .mappedRequestHeaders("http_*") 
          .routingKeyExpression("headers['routingKey']") 
         ) 
       .get(); 
    }  

    @Bean 
    public IntegrationFlow amqpInboundGateway(ConnectionFactory connectionFactory) 
    { 
     return IntegrationFlows.from 
       (
        Amqp.inboundGateway(connectionFactory, inboundQueue) 
         .mappedRequestHeaders("http_*") 
         .messageConverter(jsonMessageConverter()) 
       ) 
       .channel("inbound") 
       .get(); 
    } 

    @Bean 
    public IntegrationFlow httpOutboundGateway() 
    { 
     return IntegrationFlows.from("inbound").handle(Http.outboundGateway(urlExpression)).get(); 
    } 

私は今、私はhttp://localhost:9000/tunnelに移動する場合は、次のさを取得していますエラー:

org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'httpInboundGateway' is expected to be of type 'org.springframework.web.HttpRequestHandler' but was actually of type 'org.springframework.integration.dsl.StandardIntegrationFlow' 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:378) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1087) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at org.springframework.web.context.support.HttpRequestHandlerServlet.init(HttpRequestHandlerServlet.java:57) ~[spring-web-4.3.6.RELEASE.jar:4.3.6.RELEASE] 
    at javax.servlet.GenericServlet.init(GenericServlet.java:158) ~[tomcat-embed-core-8.5.11.jar:8.5.11] 
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1183) ~[tomcat-embed-core-8.5.11.jar:8.5.11] 
    at  

    } 

答えて

1

.handle(Http.inboundGateway("/tunnel"))

あなたは.handle()メソッドからインバウンドゲートウェイを呼び出すことはできません。

インバウンドエンドポイントはコンシューマではありません。

.from(Http.in...)のようです。

amqp着信エンドポイントと同じ問題があります。

+0

ありがとうございました。その問題は修正されました。アプリケーションは今起動しますが、http:// localhost:9000/tunnelを押すと、次の例外が発生します。 'httpInboundGateway'という名前のBeanは 'org.springframework.web.HttpRequestHandler'タイプであることが予想されますが、実際には 'org .springframework.integration.dsl.StandardIntegrationFlow ' –

+0

あなたの質問にあなたの設定を修正してください。 DSL仕様オブジェクトを実際の統合コンポーネントに解決するには、 '.get()'を呼び出さなければならないことに注意してください。 –

+0

リビジョンを投稿しました。多分、ServletRegistrationBeanは正しいアプローチではなく、特定のタイプのBeanを期待しているかもしれません。確かに。 –

関連する問題