Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring context broken when migrating on 1.1.4 / Missing docs #569

Closed
anthonime opened this issue Aug 12, 2013 · 21 comments
Closed

Spring context broken when migrating on 1.1.4 / Missing docs #569

anthonime opened this issue Aug 12, 2013 · 21 comments

Comments

@anthonime
Copy link

When upgrading from 1.1.3 to 1.1.4, my working cucumber-spring project is now broken with message like:

Caused by: java.lang.IllegalArgumentException: Cannot load an ApplicationContext with a NULL 'contextLoader'. Consider annotating your test class with @ContextConfiguration.

The cucumber.xml file is not needed any more.
The Steps java file need to be annotated with @ContextConfiguration.

The documentation / examples should be updated to demonstrate the new way of running cucumber-jvm with a Spring context.

@ffbit
Copy link
Contributor

ffbit commented Aug 12, 2013

Here you are a Spring example which shows that new way of running Cucumber JVM with Spring Framework

@ghost ghost assigned ffbit Aug 19, 2013
@aslakhellesoy
Copy link
Contributor

What's the status of this issue? Does @ffbit's example address it ok?

@ffbit
Copy link
Contributor

ffbit commented Sep 2, 2013

It seems to me that it will be nice to have documentation describing Spring Cucumber integration and some migration notes in readme.md under spring maven module.
I'm going to write it in a couple of days.
What do you think about this?

@aslakhellesoy
Copy link
Contributor

I think that would be awesome. Thanks for volunteering @ffbit

@hangvar
Copy link

hangvar commented Sep 5, 2013

I'm really eager to read the migration notes since we're experiencing some spring transactional problems with 1.1.4. When do you think you're writing them @ffbit?

@ffbit
Copy link
Contributor

ffbit commented Sep 5, 2013

@hangvar I'm sorry for the delay, I really hope to finish them by/during this weekend.

@hangvar
Copy link

hangvar commented Oct 1, 2013

No update on this @ffbit?

@pasviegas
Copy link
Contributor

Hey @hangvar can you tell me what problems? I may be able to help you.

@DavidGangel
Copy link

Hi all,

I just upgraded the cucumber-java and cucumber-spring (including all dependent other cucumber stuff) from 1.1.2 to 1.1.5.
I'm using spring as you can see. After that upgrade I faced into 2 issues. The first is described in this thread.
The other is that when I have @Autowired a step definition into another that wasn't working. I mean the container said can find the bean definition. Log:
cucumber.runtime.CucumberException: Error creating bean with name 'com.txtr.automater.tests.steps.SessionHandling.SessionHandlingStepsdef': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.txtr.automater.tests.steps.applicationHandler.ApplicationHandlerStepsdef com.txtr.automater.tests.steps.SessionHandling.SessionHandlingStepsdef.applicationHandlerSteps; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.txtr.automater.tests.steps.applicationHandler.ApplicationHandlerStepsdef] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at cucumber.runtime.java.spring.SpringFactory.getTestInstance(SpringFactory.java:161)
at cucumber.runtime.java.spring.SpringFactory.getInstance(SpringFactory.java:141)
at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:35)
at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:38)
at cucumber.runtime.Runtime.runStep(Runtime.java:289)
at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:40)
at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:83)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:82)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:41)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at cucumber.api.junit.Cucumber.run(Cucumber.java:87)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.txtr.automater.tests.steps.SessionHandling.SessionHandlingStepsdef': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.txtr.automater.tests.steps.applicationHandler.ApplicationHandlerStepsdef com.txtr.automater.tests.steps.SessionHandling.SessionHandlingStepsdef.applicationHandlerSteps; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.txtr.automater.tests.steps.applicationHandler.ApplicationHandlerStepsdef] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1120)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:379)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:110)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:313)
at cucumber.runtime.java.spring.SpringFactory.getTestInstance(SpringFactory.java:153)
... 32 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.txtr.automater.tests.steps.applicationHandler.ApplicationHandlerStepsdef com.txtr.automater.tests.steps.SessionHandling.SessionHandlingStepsdef.applicationHandlerSteps; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.txtr.automater.tests.steps.applicationHandler.ApplicationHandlerStepsdef] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
... 38 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.txtr.automater.tests.steps.applicationHandler.ApplicationHandlerStepsdef] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:967)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:837)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:749)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
... 40 more

It was working with 1.1.2 without any kind of code addition.
The only way that I can fix this by adding the @service annotation for the required steps that I want to autowire.
I can do this temporally but it will also mean that I'm bounded more closely to spring so I think this is a task for the cucumber itself as it was done in the previous version.

@mmalmeida
Copy link
Contributor

I'm upgrading cucumber. Upon upgrading from 1.1.3 to 1.1.4 I'm having this issue.

I've tried the adding the following annotations to all my stepdefs files:
@WebAppConfiguration @ContextConfiguration("classpath:cucumber.xml")

and
@ContextConfiguration

But none is working - I still get the exception.
I haven't found anything in the docs yet referring to this. What is the status on the examples?

@pasviegas
Copy link
Contributor

What is the exception?
Do you have the stacktrace of the problem?

@mmalmeida
Copy link
Contributor

@pasviegas

On 1.1.4.
* My test class:*

import org.junit.runner.RunWith;

import cucumber.api.junit.Cucumber;
import cucumber.api.junit.Cucumber.Options;

@RunWith(Cucumber.class)
@Options(
        features={"classpath:securityFeatures"},
        glue = {"security.acceptance","cucumber.api.spring"}, 
        tags = { "~@currentIteration", "~@visualInspection", "~@inLocalDevelopment", "~@futureIteration"})
public class Acceptance_Test {
}

And my stepdefs are currently annotated with:
@ContextConfiguration("classpath:cucumber.xml")
_The stacktrace:_

cucumber.runtime.CucumberException: Failed to load ApplicationContext
    at cucumber.runtime.java.spring.SpringFactory.getTestInstance(SpringFactory.java:87)
    at cucumber.runtime.java.spring.SpringFactory.getInstance(SpringFactory.java:75)
    at cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:59)
    at cucumber.runtime.Runtime.runHookIfTagsMatch(Runtime.java:195)
    at cucumber.runtime.Runtime.runHooks(Runtime.java:183)
    at cucumber.runtime.Runtime.runBeforeHooks(Runtime.java:173)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:36)
    at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:83)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:77)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:37)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:82)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
    at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122)
    at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:105)
    at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:74)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:312)
    at cucumber.runtime.java.spring.SpringFactory.getTestInstance(SpringFactory.java:84)
    ... 31 more
Caused by: java.lang.IllegalArgumentException: Cannot load an ApplicationContext with a NULL 'contextLoader'. Consider annotating your test class with @ContextConfiguration or @ContextHierarchy.
    at org.springframework.util.Assert.notNull(Assert.java:112)
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:57)
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
    ... 36 more

cucumber.runtime.CucumberException: Failed to load ApplicationContext
    at cucumber.runtime.java.spring.SpringFactory.getTestInstance(SpringFactory.java:87)
    at cucumber.runtime.java.spring.SpringFactory.getInstance(SpringFactory.java:75)
    at cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:59)
    at cucumber.runtime.Runtime.runHookIfTagsMatch(Runtime.java:195)
    at cucumber.runtime.Runtime.runHooks(Runtime.java:183)
    at cucumber.runtime.Runtime.runAfterHooks(Runtime.java:177)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:42)
    at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:83)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:77)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:37)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:82)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
    at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122)
    at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:105)
    at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:74)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:312)
    at cucumber.runtime.java.spring.SpringFactory.getTestInstance(SpringFactory.java:84)
    ... 31 more
Caused by: java.lang.IllegalArgumentException: Cannot load an ApplicationContext with a NULL 'contextLoader'. Consider annotating your test class with @ContextConfiguration or @ContextHierarchy.
    at org.springframework.util.Assert.notNull(Assert.java:112)
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:57)
    at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
    ... 36 more

@pasviegas
Copy link
Contributor

It really seems that you have a stepdef class without the @ContextConfiguration annotation.

If you don't have spring configurations classes you could update to version 1.1.5 and remove the @ContextConfiguration from the stepdefs, I think it should also work.

@mmalmeida
Copy link
Contributor

I'm actually on my way to 1.1.5 but am stuck with another error there (latest message on the mailing list, can you have a look? Issue #637 )
Currently searching for any StepDef without the annotation in the classpath.

Pedro Antonio Souza Viegas notifications@github.com wrote:

It really seems that you have a stepdef class without the
@ContextConfiguration annotation.

If you don't have spring configurations classes you could update to
version 1.1.5 and remove the @ContextConfiguration from the stepdefs, I
think it should also work.


Reply to this email directly or view it on GitHub:
#569 (comment)

Sent from my Android phone with K-9 Mail. Please excuse my brevity.

@mkhatri
Copy link

mkhatri commented Nov 27, 2013

I'm updating cucumber to 1.1.5 and received NPE in my spring project i.e. @Autowired is not working. Is there any update for the resolution?

@pasviegas
Copy link
Contributor

Hey @mmalmeida if you are using the hooks you'll probably need the @ContextConfiguration anyways.

The example for that is on examples/spring-txn.

If you can also share a project on github, I could try to help you better.

Thanks

@mmalmeida
Copy link
Contributor

@pasviegas - I believe the example on examples/spring-txn is broken - see #637 .

I comment on the need to use @ContextConfiguration there as well (which is why the example is actually broken).

@mmalmeida
Copy link
Contributor

@aslakhellesoy ffbit's example shows how to use the @ContextConfiguration, but since the transaction hook glue path is wrong it actually exposes a new problem - either you annotate the Spring hook with @ContextConfiguration(cucumber.xml) and it will only work when you use cucumber.xml; or you don't annotate it and - right now - you end up with a class you can't use (NPE). I added #637 to specifically address this, although the documentation referenced here is also related to it.

@tuxbox
Copy link

tuxbox commented Jan 23, 2014

Sorry, but breaking compatability here is really bad. If you have 100s of steps which all run with a single cucumber.xml perfectly, you're now forced to annotate every single step?? That just makes it harder. It should be optional to annotate your steps.
If no annotation is present use the default up to 1.1.3 and if an annotation is present, use it instead of the default context.
But this breaking "feature" is not improving cucumber at all.

@paoloambrosio
Copy link
Member

Solved by #711. Separate issue #724 for docs exists.

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot unassigned ffbit Oct 25, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants