Failing to run tests because of Conflicting Bean Definition Exception

Heilo,i am running a test within the meta deploy module but i get exception below.I have tried to look for the beans as per the error but cannot find them.Any clue??

https://pastebin.com/DtVCvbPh

org.openmrs.validator.OrderTypeValidator
conflicts with existing, non-compatible bean definition of same name and class org.openmrs.web.controller.order.OrderTypeValidator

Could you check what those two classes are, in which project each of them live… etc? This will give yo a clue as to why you experience this collision.

Without looking further it looks like a class that was moved around pre and post Core 2.x, and somehow you are in an environment that holds both.

@mksd okie thanks let me look through them

Am trying to solve the same error , But i would think Spring would by default give a precedence to xml defined beans over the annotation defined beans.
Am creating a new sub-project in the Reporting module that depends on 2+ core version. So thats what has brought up the conficting issue in my case

I finally solved this after a long struggle , i made sure i do exclusions in the pom to make sure i only have one single version of the openmrs-api in my enviroment,

1 Like

@mozzy How did you resolve the issue I seem to be having the same blocker with my work on the HTML Form Entry ProgramAttribute tag here https://github.com/openmrs/openmrs-module-htmlformentry/pull/173

Thanks in advance

@ssmusoke , im my case i was adding a new conditional resource2.2 in the reporting module see work done ,

it was heavily due to conflicting bean definitions , that is between xml definitions in pre-2.2 core version and Annotation definition in 2.2 core version.

I solved it by deeply and carefully looking at the dependency definitons in the Parent Pom and the Child POM of sub resource 2.2.
The idea is ensure the Child POM file for sub resource 2.2 entirely depends on Core 2.2 API only. theres a tendence where it will both pull dependencis from core 2.2 and core pre-2.2 version ,and that will cause Conflicts , because in core 2.2. some spring bean definitions were switched to annotation rather than XML.

You can actually add exclusions in the Child POM to exclude any component that is still inherited by child POM from the Parent pom

@mozzy Whatever you are saying is Greek to me, is there any guide or just trial and error

@ssmusoke , ok lets go a little more practicle

when you just take a look at the Jars(dependencies) pulled in your htmlformentry api-2.2 , Arent there any OpenMRS Core dependencies for version pre-2.2 ??

@mozzy There are no pre-2.2 versions https://github.com/openmrs/openmrs-module-htmlformentry/blob/5b397402fcbf0f85086715b85e226b3530d040bb/api-2.2/pom.xml

1 Like

@ssmusoke , i was saying in the Actual IDE , physically looking at pulled dependencies ??

@mozzy The module has profiles for 1.10, 2.0, 2.1 and 2.2 so pre-2.2 dependencies will exist see below

1 Like

@ssmusoke, are those the dependencies for sub-module 2.2 specifically ??

So for the case of sub-module 2.2 , we would want to configure the child POM for sub-module 2.2 so that , it doesnt pull any openmrs-api dependency for pre-2.2 version.

That may also call for adding <exclusions> in the child POM for sub-module 2.2 if possible , in order to avoid conflicting bean definition in 2.2 against pre-2.2 ,

@mozzy those are for the whole module

@mozzy Now that was helpful as I now see for the module OpenMRS web 1.9.9 which may be the root cause of the issue, however I do not see it being brought in so let me find out where it comes from

1 Like

@ssmusoke , you added in this dependence ,which inherits a version from the Parent POM file. Am sure the thats where OpenMRS web 1.9.9 is inherited from.

       <dependency>
            <groupId>${project.parent.groupId}</groupId>
            <artifactId>${project.parent.artifactId}-api-tests</artifactId>
            <version>${project.parent.version}</version>
            <type>test-jar</type>
            <scope>test</scope>
        </dependency>

You may want to simply use <exclusion> to exclude the web 1.9.9 from sub-module 2.2

@mozzy that worked as I was able to get the correct version of the openmrs-web with exclusions and an explicit inclusion as below

<dependency>
    <groupId>${project.parent.groupId}</groupId>
    <artifactId>${project.parent.artifactId}-api</artifactId>
    <version>${project.parent.version}</version>
    <scope>provided</scope>
    <exclusions>
        <exclusion>
            <groupId>org.openmrs.web</groupId>
            <artifactId>openmrs-web</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>${project.parent.groupId}</groupId>
    <artifactId>${project.parent.artifactId}-api-tests</artifactId>
    <version>${project.parent.version}</version>
    <type>test-jar</type>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>org.openmrs.web</groupId>
            <artifactId>openmrs-web</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.openmrs.web</groupId>
    <artifactId>openmrs-web</artifactId>
    <version>${openMRSVersion}</version>
    <type>test-jar</type>
    <scope>test</scope>
</dependency>
2 Likes

That great @ssmusoke :slightly_smiling_face: