title: Cucumber Spring DI two Step classes loading Spring context
body: <p>I'm using cucumber-spring to create my integration tests and use DI provided by Spring.
  The way it's done: there is a separate project that defines all the necessary cucumber dependencies:</p>
  
  <pre><code>&lt;dependency&gt;
             &lt;groupId&gt;io.cucumber&lt;/groupId&gt;
             &lt;artifactId&gt;cucumber-java&lt;/artifactId&gt;
             &lt;version&gt;${cucumber.version}&lt;/version&gt;
         &lt;/dependency&gt;
         &lt;dependency&gt;
             &lt;groupId&gt;io.cucumber&lt;/groupId&gt;
             &lt;artifactId&gt;cucumber-spring&lt;/artifactId&gt;
             &lt;version&gt;${cucumber.version}&lt;/version&gt;
         &lt;/dependency&gt;
         &lt;dependency&gt;
             &lt;groupId&gt;io.cucumber&lt;/groupId&gt;
             &lt;artifactId&gt;cucumber-junit&lt;/artifactId&gt;
             &lt;version&gt;${cucumber.version}&lt;/version&gt;
         &lt;/dependency&gt;
  </code></pre>
  
  <p>The project also has a base test class annotated with SpringBootTest (that allows to load application context):</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest(
      classes = {SomeBeans.class}
  )
  public class BaseTestStateSteps {
  </code></pre>
  
  <p>I'm adding this project as a dependency in the pom of my project:</p>
  
  <pre><code>&lt;dependency&gt;
     &lt;groupId&gt;com.externalproject&lt;/groupId&gt;
     &lt;artifactId&gt;spring-test-cucumber&lt;/artifactId&gt;
     &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>Then I have my runner class:</p>
  
  <pre><code>@RunWith(Cucumber.class)
  @CucumberOptions(
          plugin = {"pretty", "junit:target/cucumber/cucumber.xml", "json:target/cucumber/cucumber.json",
                  "html:target/cucumber/html/"},
          tags = {"@Smoke"},
          features = {"src/test/resources/features"},
          glue = {"com.externalproject.steps","com.mycompany.steps"}
  )
  public class RunTestIT {
  }
  </code></pre>
  
  <p>And I also have my Step class:</p>
  
  <pre><code>public class MyTestSteps {
  
      @Autowired
      ClassToAutowire classToAutowire;
  
      @Given("^I can do something$")
      public void generateRandomPhoneNumber() {
          classToAutowirer.doSomething();
      }
  </code></pre>
  
  <p>So the issue I'm running:
  - if I don't have my RunTestIT annotated with SpringBootTest or with ContextConfiguration - ClassToAutowire is null (it's not autowired);
  - if I addone of those annotations I'm running into error:</p>
  
  <pre><code>cucumber.runtime.CucumberException: Glue class class com.externalproject.steps.BaseTestStateSteps and class com.mycompany.steps.MyTestSteps both attempt to configure the spring context. Please ensure only one glue class configures the spring context
  </code></pre>
  
  <p>I need the functionality of Steps from external project (so I don't have to copy/paste from there and get the latest feature updates), but I also need dependencies from my spring context to be autowired.</p>
  
  <p>I read the article <a href="https://thepracticaldeveloper.com/2018/03/31/cucumber-tests-spring-boot-dependency-injection/" rel="nofollow noreferrer">https://thepracticaldeveloper.com/2018/03/31/cucumber-tests-spring-boot-dependency-injection/</a>
  But it only deals with multiple step definitions inside the same project.</p>
  
  <p>Do you have any ideas how I can solve the issue?</p>