title: error while running integration test with spring boot and testng
body: <p>We are trying to run integration test using testng and springboot.app is running fine and we are able run standalone test using eclipse.but when we run testcase using maven command line.i am getting following exception </p>
  
  <pre><code>org.apache.coyote.AbstractProtocol start
  SEVERE: Failed to start end point associated with ProtocolHandler ["http-nio-8080"]
  java.net.BindException: Address already in use: bind
          at sun.nio.ch.Net.bind0(Native Method)
          at sun.nio.ch.Net.bind(Net.java:433)
          at sun.nio.ch.Net.bind(Net.java:425)
  </code></pre>
  
  <p>if we try to load context.xml for running testcase then each testcase is trying to load its own context and testcase are failing with host not found exception.</p>
  
  <p>base testcase class</p>
  
  <pre><code>//@ContextConfiguration(locations={"classpath:objectModelContext.xml"})
  @RunWith(SpringRunner.class)
  @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  public class BaseITCase extends com.test.common.BaseITCase {
  
      protected static final String baseUrl = "http://localhost:" +  port + "/test/api/";
  
      protected String getAdminToken(String username, String password, String deviceId) throws Exception {
      }
  }
  </code></pre>
  
  <p>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;om.test&lt;/groupId&gt;
  &lt;artifactId&gt;springboot&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;packaging&gt;jar&lt;/packaging&gt;
  &lt;name&gt;springboot&lt;/name&gt;
  &lt;url&gt;http://maven.apache.org&lt;/url&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.4.1.RELEASE&lt;/version&gt;
  &lt;/parent&gt;
  &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;start-class&gt;com.test.App&lt;/start-class&gt;
      &lt;tomcat.version&gt;7.0.65&lt;/tomcat.version&gt;
  &lt;/properties&gt;
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.reflections&lt;/groupId&gt;
          &lt;artifactId&gt;reflections-maven&lt;/artifactId&gt;
          &lt;version&gt;0.9.9-RC2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-velocity&lt;/artifactId&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;
                  &lt;artifactId&gt;logback-classic&lt;/artifactId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
                  &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
          &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
          &lt;version&gt;9.4-1200-jdbc41&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;
                  &lt;artifactId&gt;logback-classic&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;!-- only dependency needed --&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-jersey&lt;/artifactId&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;
                  &lt;artifactId&gt;logback-classic&lt;/artifactId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
                  &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.googlecode.plist&lt;/groupId&gt;
          &lt;artifactId&gt;dd-plist&lt;/artifactId&gt;
          &lt;version&gt;1.8&lt;/version&gt;
          &lt;!-- corresponds to r108 --&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
          &lt;artifactId&gt;httpmime&lt;/artifactId&gt;
          &lt;type&gt;jar&lt;/type&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;!-- Test --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-test&lt;/artifactId&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-test&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.testng&lt;/groupId&gt;
          &lt;artifactId&gt;testng&lt;/artifactId&gt;
          &lt;version&gt;6.8.13&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.assertj&lt;/groupId&gt;
          &lt;artifactId&gt;assertj-core&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.shiro&lt;/groupId&gt;
          &lt;artifactId&gt;shiro-web&lt;/artifactId&gt;
          &lt;version&gt;1.2.4&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.2&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;source&gt;1.8&lt;/source&gt;
                  &lt;target&gt;1.8&lt;/target&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;id&gt;pre-integration-test&lt;/id&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;start&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
                  &lt;execution&gt;
                      &lt;id&gt;post-integration-test&lt;/id&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;stop&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
              &lt;configuration&gt;
                  &lt;maxAttempts&gt;600&lt;/maxAttempts&gt;
                  &lt;fork&gt;true&lt;/fork&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-failsafe-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.19.1&lt;/version&gt;
              &lt;!--$NO-MVN-MAN-VER$--&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;id&gt;integration-tests&lt;/id&gt;
                      &lt;phase&gt;integration-test&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;integration-test&lt;/goal&gt;
                          &lt;goal&gt;verify&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>Update</strong></p>
  
  <p>Tests are run using <code>mvn clean install</code></p>
  
  <p>i am trying to look for example for same but i am not finding any solution.</p>