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

Sporadic IllegalStateException #209

jimcakalic opened this Issue Feb 17, 2017 · 4 comments


None yet
3 participants
Copy link

jimcakalic commented Feb 17, 2017

I'm new to Citrus but very impressed so far. We're trying to use the Cucumber integration with supplied glue. I've been seeing a sporadic "java.lang.IllegalStateException: Unable to initialize Citrus instance - instance has already been initialized" when running the IT as a JUnit test on my development system (Windows/Eclipse) and sometimes less frequently when running the Maven integration-test goal, again on my local system. The problem is much worse in our Jenkins environment. I can't get a clean project build that exercises the tests because it always fails with the IllegalStateException. I'm using Citrus 2.6.2 and JDK 1.7, though I tried Citrus 2.7 and JDK 1.8 with no appreciable difference. Not sure what else you need to know or what files you need me to post. Already RTFM and STFW with no helpful results.

citrus-context.xml -- only defining a single HTTP endpoint that uses basic auth.
cucumber.xml -- exactly as found in the user guide -- only defines '' to prevent the properties not found message --

The cucumber feature file is pretty simple with only one scenario that sends and receives a message on an autowired Spring endpoint defined in citrus-context and a background that defines the the request message and response message templates used by the scenario.

I have a demo to senior management on Monday and wanted to show off Citrus and Cucumber in Jenkins but can't get it to work and starting to get a little desperate. I'll be watching the board through the weekend should anyone have a suggestion or need more information. Thanks!


This comment has been minimized.

Copy link

christophd commented Feb 19, 2017

First question: do you need to use Spring autowiring in StepDefinition classes? If not use

Secondly your initialization is called multiple times unexpectedly. So Citrus runtime is loaded at least twice and the error is raised. So you may need to give your Cucumber Java class that loads the Spring application context. I would expect something like:

public class MyFeatureIT {

In the step definitions you may use something like:

@ContextConfiguration(classes = CitrusSpringConfig.class)
public class MySteps {

Do you have multiple StepDefinition classes? You should have @ContextConfiguration annotation set only once per feature package.


This comment has been minimized.

Copy link

jimcakalic commented Feb 19, 2017

Thanks, Christoph.

Changing the ObjectFactory did the trick. We were using custom steps classes but I wanted to see how far we could get with using the provided steps. I thought I had tried changing this property but it was a long day Friday. It's good to know that the ContextConfiguration annotation can appear on only one feature per package.

My remaining problems appear to be Jenkins or application related now. Thanks again for your quick response.

@jimcakalic jimcakalic closed this Feb 19, 2017

@christophd christophd removed the READY label Feb 19, 2017


This comment has been minimized.

Copy link

christophd commented Feb 20, 2017

Some additional note: When using cucumber-spring in combination with Citrus please make sure that cucumber-spring library is loaded in classpath before Citrus. You can put the cucumber-spring dependency in Maven POM before Citrus dependency. This should also fix the IllegalStateException when executing tests with Maven. Also in IntelliJ you can fix the classpath order of libraries loaded.

This is because cucumber-spring initialization should be done before the Citrus cucumber extension is loaded. Only the the Spring application context setup is done properly. In case you do not use cucumber-spring you can ignore all of this.

@christophd christophd added this to the v2.7.1 milestone Feb 20, 2017

christophd added a commit that referenced this issue Feb 20, 2017


This comment has been minimized.

Copy link

taz77 commented Mar 28, 2017

This fixed a sporadic issue we had where the tests would error out say "Unable to initialize Citrus instance - instance has already been initialized". We are using Cucumber. Veilen Dank!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.