CucumberException: Annotations differs on glue classes found

1,676 views
Skip to first unread message

Eugene Shragovich

unread,
Sep 14, 2017, 5:37:01 AM9/14/17
to Cukes
Greetings, 


I have this issue after upgrading to Cucumber 1.2.5 from 1.1.8

I already found some posts that seem to discuss the same issue here:

and also here:


From all that I understand that this error is returned if two classes have different @ContextHierarchy/@ContextConfiguration annotations.
In my case however, I have only one class annotated with @ContextHierarchy({@ContextConfiguration("classpath:/cucumber.xml")}), and the rest of the glue classes extend this class and do not contain any such annotations themselves.


The parent class looks like this:

@ContextHierarchy({@ContextConfiguration("classpath:/cucumber.xml")})
@Component
public abstract class BddGlue {

}

And the glue classes just extend it so there is no duplication of mixing of different annotations. Nevertheless, I still get the above mentioned error.

Can you please advise what am I doing wrong here?


Thanks!
Eugene

Björn Rasmusson

unread,
Sep 14, 2017, 7:07:30 AM9/14/17
to Cukes

Since you do not show the declaration of the classes that Cucumber-JVM complains about, it is impossible to say what you are doing wrong.

/Björn


Thanks!
Eugene

Eugene Shragovich

unread,
Sep 15, 2017, 12:22:47 AM9/15/17
to Cukes
Hi and thanks for the reply,

I think I was able to understand what was causing the issue. Not all the classes that inherit from BddGlue had been annotated with @Component. I thought that only @ContextHierarchy({@ContextConfiguration("classpath:/cucumber.xml")}) annotation must be equal.


The problem now is that not all of my classes that inherit from BddGlue should be annotated with @Component but it seems I am now forced into doing that. Is that correct?


Thanks,
Eugene

Björn Rasmusson

unread,
Sep 15, 2017, 2:42:49 AM9/15/17
to Cukes
Eugene Shragovich wrote:
Hi and thanks for the reply,

I think I was able to understand what was causing the issue. Not all the classes that inherit from BddGlue had been annotated with @Component. I thought that only @ContextHierarchy({@ContextConfiguration("classpath:/cucumber.xml")}) annotation must be equal.

Cucumber-JVM uses one glue class to create the spring context. Cucumber-JVM cannot know which annotations, besides @ContextConfiguration and @ContextHierarchy, that affect the spring context created, therefore the list of all annotations on the classes which have @ContextConfiguration and @ContextHierarchy annotations must be equal. The Cucumber-JVM can be sure that it does not matter which of these classes it uses to create the spring context.

 


The problem now is that not all of my classes that inherit from BddGlue should be annotated with @Component but it seems I am now forced into doing that. Is that correct?

All classes which have @ContextConfiguration and @ContextHierarchy annotations (in your case that inherit from BddGlue) must have exactly the same annotations on them. However all glue classes does not need to have @ContextConfiguration and @ContextHierarchy annotations, Cucumber-JVM must only find (at least) one. The solution in your case seems to be to remove the inheritance from BddGlue on all classes that should be annotated with @Component (or remove the inheritance from BddGlue on all classes that should not be annotated with @Component).

/Björn
 

Eugene Shragovich

unread,
Sep 15, 2017, 3:33:18 AM9/15/17
to Cukes
Thank you very much Björn,

I have made few changes based ion your recommendations and it seem like I have been able to resolve this problem.


Best Regards,
Eugene

Mridul Jayan

unread,
Jun 5, 2018, 9:40:44 AM6/5/18
to Cukes
I was able to solve this problem by adding a step definition as below along with the other step definitions. This is not used by any other step definitions.

@Slf4j
@ContextConfiguration(classes = Application.class)
public class ContextSteps {
@Before
public void dummy() {
log.info("Used to load spring context for cucumber due to constraints! Not a real step definition!");
}
}
Reply all
Reply to author
Forward
0 new messages