title: Getting Spring Integration 4.0 with Spring-Boot
body: <p>I watched this great video to help bootstrap my understanding of Spring Integration 4.0</p>
  
  <p><a href="https://www.youtube.com/watch?v=g3DgdSqEgzI" rel="nofollow">https://www.youtube.com/watch?v=g3DgdSqEgzI</a> </p>
  
  <p>Going line for line in this demo, the code doesn't work.  It's mainly due to conflicts between Spring Integration and the spring-boot-start-integration.</p>
  
  <p>Spring Initalizr doesn't provide much help either....  </p>
  
  <p>Here's the very simple code:</p>
  
  <pre><code>import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  import org.springframework.context.ConfigurableApplicationContext;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.core.env.Environment;
  import org.springframework.integration.annotation.MessageEndpoint;
  import org.springframework.integration.annotation.ServiceActivator;
  import org.springframework.integration.channel.DirectChannel;
  import org.springframework.integration.ip.tcp.TcpInboundGateway;
  import org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory;
  import org.springframework.messaging.MessageChannel;
  
  @Configuration
  @ComponentScan
  @EnableAutoConfiguration
  public class Application {
      public static void main(String[] args) throws Exception {
          ConfigurableApplicationContext ctx = SpringApplication.run(Application.class);
          System.in.read();
          ctx.close();
      }
  
      @Bean
      TcpNetServerConnectionFactory cf () {
          return new TcpNetServerConnectionFactory(9876);
      }
  
      @Bean
      TcpInboundGateway tcpGate() {
          TcpInboundGateway gateway = new TcpInboundGateway();
          gateway.setConnectionFactory(cf());
          gateway.setRequestChannel(requestChannel());
          return gateway;
      }
  
      @Bean
      public MessageChannel requestChannel() {
          return new DirectChannel();
      }
  
      @MessageEndpoint
      public static class Echo {
          @ServiceActivator(inputChannel = "requestChannel")
          public String echo(byte [] in) {
              return "echo: " + new String(in);
          }
      }
  
      @Autowired
      private Environment env;
  }
  </code></pre>
  
  <p>And here's the pom.xml.</p>
  
  <pre><code>&lt;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"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;xsoft-examples&lt;/groupId&gt;
  &lt;artifactId&gt;xsoft-examples-integration&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;name&gt;demo&lt;/name&gt;
  &lt;description&gt;Spring Integration Demo&lt;/description&gt;
  &lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;1.0.2.RELEASE&lt;/version&gt;
      &lt;relativePath/&gt;
      &lt;!--  lookup parent from repository  --&gt;
  &lt;/parent&gt;
  &lt;dependencies&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.integration&lt;/groupId&gt;
          &lt;artifactId&gt;spring-integration-core&lt;/artifactId&gt;
          &lt;version&gt;4.0.1.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.integration&lt;/groupId&gt;
          &lt;artifactId&gt;spring-integration-ws&lt;/artifactId&gt;
          &lt;version&gt;4.0.1.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.integration&lt;/groupId&gt;
          &lt;artifactId&gt;spring-integration-xml&lt;/artifactId&gt;
          &lt;version&gt;4.0.1.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.integration&lt;/groupId&gt;
          &lt;artifactId&gt;spring-integration-ip&lt;/artifactId&gt;
          &lt;version&gt;4.0.1.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-test&lt;/artifactId&gt;
          &lt;version&gt;4.0.3.RELEASE&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
  &lt;/dependencies&gt;
  &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;start-class&gt;com.xsoft.demo.Application&lt;/start-class&gt;
      &lt;java.version&gt;1.7&lt;/java.version&gt;
  &lt;/properties&gt;
  &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p></p>
  
  <p>And when I connect to port 9876 via telnet and send a "hello" string, I get...</p>
  
  <pre><code>org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'application.requestChannel'.
  </code></pre>