How to get rid of the conversionServicePostProcessor bean conflict?

3k views Asked by At

I've got a project with the following dependencies:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-logging</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-hateoas</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>

    <!-- Streaming/Kafka -->
    <dependency>
        <groupId>io.projectreactor.kafka</groupId>
        <artifactId>reactor-kafka</artifactId>
        <version>1.1.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.apache.kafka</groupId>
        <artifactId>kafka-clients</artifactId>
        <version>2.0.0</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.kafka</groupId>
        <artifactId>spring-kafka</artifactId>
    </dependency>

    <!-- JPA -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <exclusions>
            <exclusion>
                <!--
                HikariCP is excluded so tomcat connection is used.
                This is necessary to set "connection-properties: v$session.program" param
                -->
                <groupId>com.zaxxer</groupId>
                <artifactId>HikariCP</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.flywaydb.enterprise</groupId>
        <artifactId>flyway-core</artifactId>
        <version>6.2.4</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>oracle</groupId>
        <artifactId>oracle-jdbc</artifactId>
        <version>11.2g</version>
    </dependency>


    <!-- Spring Doc -->
    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-common</artifactId>
        <version>${spring-doc.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-webmvc-core</artifactId>
        <version>${spring-doc.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-security</artifactId>
        <version>${spring-doc.version}</version>
    </dependency>

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
    </dependency>
    <dependency>
        <groupId>com.ibm.icu</groupId>
        <artifactId>icu4j</artifactId>
        <version>62.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-configuration-processor</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-stream-test-support</artifactId>
        <scope>test</scope>
    </dependency>

    <!-- security -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

    <!-- oauth -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-oauth2-jose</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-oauth2-resource-server</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>


    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>
    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-core</artifactId>
        <version>${reactor.version}</version>
    </dependency>
    <dependency>
        <groupId>io.projectreactor.addons</groupId>
        <artifactId>reactor-extra</artifactId>
        <version>${reactor.version}</version>
    </dependency>

    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>javax.interceptor</groupId>
        <artifactId>javax.interceptor-api</artifactId>
        <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.dataformat</groupId>
        <artifactId>jackson-dataformat-yaml</artifactId>
        <version>${jackson.version}</version>
    </dependency>

    <dependency>
        <groupId>com.squareup.okhttp3</groupId>
        <artifactId>mockwebserver</artifactId>
        <version>${okhttp3.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.9</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib</artifactId>
        <version>${kotlin.version}</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-reflect</artifactId>
        <version>${kotlin.version}</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-test-junit</artifactId>
        <version>${kotlin.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.3</version>
            </plugin>
        </plugins>
    </pluginManagement>

    <resources>
        <resource>
            <directory>${project.basedir}/target/ansible_sources</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/vars.yml</include>
            </includes>
        </resource>
        <resource>
            <directory>${project.basedir}/src/main/resources</directory>
            <filtering>true</filtering>
            <excludes>
                <exclude>**/*.jks</exclude>
            </excludes>
        </resource>
        <resource>
            <directory>${project.basedir}/src/main/resources</directory>
            <filtering>false</filtering>
            <includes>
                <include>**/*.jks</include>
            </includes>
        </resource>
    </resources>

    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>build-info</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>pl.project13.maven</groupId>
            <artifactId>git-commit-id-plugin</artifactId>
            <version>2.2.6</version>
        </plugin>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.1</version>
            <executions>
                <execution>
                    <id>default-prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>default-report</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-plugin</artifactId>
            <version>${kotlin.version}</version>
            <executions>
                <execution>
                    <id>compile</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>test-compile</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <executions>
                <execution>
                    <id>compile</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>testCompile</id>
                    <phase>test-compile</phase>
                    <goals>
                       <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

dependency tree (incomplete, skipping several common dependencies to be within character limit):

 --- maven-dependency-plugin:3.1.1:tree (default-cli) @ projectName ---

 projectName:jar:0.0.12-SNAPSHOT


 +- org.springframework.cloud:spring-cloud-starter-openfeign:jar:2.2.4.RELEASE:compile

 |  +- org.springframework.cloud:spring-cloud-starter:jar:2.2.4.RELEASE:compile

 |  |  +- org.springframework.cloud:spring-cloud-context:jar:2.2.4.RELEASE:compile

 |  |  \- org.springframework.security:spring-security-rsa:jar:1.0.9.RELEASE:compile

 |  |     \- org.bouncycastle:bcpkix-jdk15on:jar:1.64:compile

 |  +- org.springframework.cloud:spring-cloud-openfeign-core:jar:2.2.4.RELEASE:compile

 |  |  \- io.github.openfeign.form:feign-form-spring:jar:3.8.0:compile

 |  |     +- io.github.openfeign.form:feign-form:jar:3.8.0:compile

 |  |     \- commons-fileupload:commons-fileupload:jar:1.4:compile

 |  +- org.springframework:spring-web:jar:5.2.3.RELEASE:compile

 |  |  \- org.springframework:spring-beans:jar:5.2.3.RELEASE:compile

 |  +- org.springframework.cloud:spring-cloud-commons:jar:2.2.4.RELEASE:compile

 |  |  \- org.springframework.security:spring-security-crypto:jar:5.2.1.RELEASE:compile

 |  +- io.github.openfeign:feign-core:jar:10.10.1:compile

 |  +- io.github.openfeign:feign-slf4j:jar:10.10.1:compile

 |  \- io.github.openfeign:feign-hystrix:jar:10.10.1:compile

 |     +- com.netflix.archaius:archaius-core:jar:0.7.6:compile

 |     \- com.netflix.hystrix:hystrix-core:jar:1.5.18:compile

 |        \- org.hdrhistogram:HdrHistogram:jar:2.1.9:compile

 +- org.springframework.boot:spring-boot-starter-hateoas:jar:2.2.3.RELEASE:compile

 |  +- org.springframework.boot:spring-boot-starter-web:jar:2.2.3.RELEASE:compile

 |  |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.2.3.RELEASE:compile

 |  |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.30:compile

 |  |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.30:compile

 |  |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.30:compile

 |  |  \- org.springframework:spring-webmvc:jar:5.2.3.RELEASE:compile

 |  \- org.springframework.hateoas:spring-hateoas:jar:1.0.3.RELEASE:compile

 |     \- org.springframework.plugin:spring-plugin-core:jar:2.0.0.RELEASE:compile

 +- org.springframework.cloud:spring-cloud-starter-netflix-ribbon:jar:2.2.4.RELEASE:compile

 |  +- org.springframework.cloud:spring-cloud-netflix-ribbon:jar:2.2.4.RELEASE:compile

 |  |  \- org.springframework.cloud:spring-cloud-netflix-archaius:jar:2.2.4.RELEASE:compile

 |  +- org.springframework.cloud:spring-cloud-starter-netflix-archaius:jar:2.2.4.RELEASE:compile

 |  |  \- commons-configuration:commons-configuration:jar:1.8:compile


 |  +- com.netflix.ribbon:ribbon-core:jar:2.3.0:compile

 |  |  \- commons-lang:commons-lang:jar:2.6:compile

 |  +- com.netflix.ribbon:ribbon-httpclient:jar:2.3.0:compile

 |  |  +- commons-collections:commons-collections:jar:3.2.2:runtime

 |  |  +- com.sun.jersey:jersey-client:jar:1.19.1:compile

 |  |  |  \- com.sun.jersey:jersey-core:jar:1.19.1:compile

 |  |  |     \- javax.ws.rs:jsr311-api:jar:1.1.1:compile

 |  |  +- com.sun.jersey.contribs:jersey-apache-client4:jar:1.19.1:compile

 |  |  +- com.netflix.servo:servo-core:jar:0.12.21:runtime

 |  |  \- com.netflix.netflix-commons:netflix-commons-util:jar:0.3.0:runtime

 |  +- com.netflix.ribbon:ribbon-loadbalancer:jar:2.3.0:compile

 |  |  \- com.netflix.netflix-commons:netflix-statistics:jar:0.1.1:runtime

 |  \- io.reactivex:rxjava:jar:1.3.8:compile

 +- org.springframework.cloud:spring-cloud-starter-config:jar:2.2.4.RELEASE:compile

 |  +- org.springframework.cloud:spring-cloud-config-client:jar:2.2.4.RELEASE:compile

 |  |  \- com.fasterxml.jackson.core:jackson-annotations:jar:2.11.0:compile

 |  \- com.fasterxml.jackson.core:jackson-databind:jar:2.11.0:compile

 +- io.projectreactor.kafka:reactor-kafka:jar:1.1.0.RELEASE:compile

 +- org.flywaydb.enterprise:flyway-core:jar:6.2.4:compile

 +- org.apache.tomcat:tomcat-jdbc:jar:9.0.30:compile

 |  \- org.apache.tomcat:tomcat-juli:jar:9.0.30:compile

 +- com.h2database:h2:jar:1.4.200:runtime

 +- oracle:oracle-jdbc:jar:11.2g:compile

 +- commons-io:commons-io:jar:2.5:compile

 +- commons-codec:commons-codec:jar:1.13:compile

 +- com.ibm.icu:icu4j:jar:62.1:compile

 +- org.apache.httpcomponents:httpclient:jar:4.5.10:compile

 |  \- org.apache.httpcomponents:httpcore:jar:4.4.13:compile

 +- org.springframework.boot:spring-boot-configuration-processor:jar:2.2.3.RELEASE:compile (optional)

 +- org.springframework.boot:spring-boot-devtools:jar:2.2.3.RELEASE:compile

 |  +- org.springframework.boot:spring-boot:jar:2.2.3.RELEASE:compile

 |  \- org.springframework.boot:spring-boot-autoconfigure:jar:2.2.3.RELEASE:compile
    
 +- org.springframework.cloud:spring-cloud-stream-test-support:jar:3.0.7.RELEASE:test

 |  \- org.springframework.cloud:spring-cloud-stream:jar:3.0.7.RELEASE:test

 |     +- org.springframework.integration:spring-integration-core:jar:5.2.3.RELEASE:test

 |     +- org.springframework.integration:spring-integration-jmx:jar:5.2.3.RELEASE:test

 |     \- org.springframework.cloud:spring-cloud-function-context:jar:3.0.9.RELEASE:test

 |        +- net.jodah:typetools:jar:0.6.2:test

 |        \- org.springframework.cloud:spring-cloud-function-core:jar:3.0.9.RELEASE:test

 +- org.springframework.boot:spring-boot-starter-security:jar:2.2.3.RELEASE:compile

 |  +- org.springframework:spring-aop:jar:5.2.3.RELEASE:compile

 |  +- org.springframework.security:spring-security-config:jar:5.2.1.RELEASE:compile

 |  \- org.springframework.security:spring-security-web:jar:5.2.1.RELEASE:compile

 +- org.springframework.security:spring-security-oauth2-jose:jar:5.2.1.RELEASE:compile

 |  +- com.nimbusds:nimbus-jose-jwt:jar:7.8:compile

 |  |  \- com.github.stephenc.jcip:jcip-annotations:jar:1.0-1:compile

 |  +- org.springframework.security:spring-security-core:jar:5.2.1.RELEASE:compile

 |  \- org.springframework.security:spring-security-oauth2-core:jar:5.2.1.RELEASE:compile

 +- org.springframework.security:spring-security-oauth2-resource-server:jar:5.2.1.RELEASE:compile

 +- org.springframework.security:spring-security-test:jar:5.2.1.RELEASE:test

 +- org.springframework.boot:spring-boot-starter-webflux:jar:2.2.3.RELEASE:compile

 |  +- org.springframework.boot:spring-boot-starter-json:jar:2.2.3.RELEASE:compile

 |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.11.0:compile

 |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.11.0:compile

 |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.11.0:compile

 |  +- org.springframework.boot:spring-boot-starter-reactor-netty:jar:2.2.3.RELEASE:compile

 |  |  +- io.projectreactor.netty:reactor-netty:jar:0.9.3.RELEASE:compile

 |  |  |  +- io.netty:netty-codec-http:jar:4.1.45.Final:compile

 |  |  |  |  +- io.netty:netty-common:jar:4.1.45.Final:compile

 |  |  |  |  +- io.netty:netty-buffer:jar:4.1.45.Final:compile

 |  |  |  |  +- io.netty:netty-transport:jar:4.1.45.Final:compile

 |  |  |  |  |  \- io.netty:netty-resolver:jar:4.1.45.Final:compile

 |  |  |  |  \- io.netty:netty-codec:jar:4.1.45.Final:compile

 |  |  |  +- io.netty:netty-codec-http2:jar:4.1.45.Final:compile

 |  |  |  +- io.netty:netty-handler:jar:4.1.45.Final:compile

 |  |  |  +- io.netty:netty-handler-proxy:jar:4.1.45.Final:compile

 |  |  |  |  \- io.netty:netty-codec-socks:jar:4.1.45.Final:compile

 |  |  |  \- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.45.Final:compile

 |  |  |     \- io.netty:netty-transport-native-unix-common:jar:4.1.45.Final:compile

 |  |  \- org.glassfish:jakarta.el:jar:3.0.3:compile

 |  +- org.springframework.boot:spring-boot-starter-validation:jar:2.2.3.RELEASE:compile

 |  |  +- jakarta.validation:jakarta.validation-api:jar:2.0.2:compile

 |  |  \- org.hibernate.validator:hibernate-validator:jar:6.0.18.Final:compile

 |  +- org.springframework:spring-webflux:jar:5.2.3.RELEASE:compile

 |  \- org.synchronoss.cloud:nio-multipart-parser:jar:1.1.0:compile

 |     \- org.synchronoss.cloud:nio-stream-storage:jar:1.1.3:compile

 +- io.projectreactor:reactor-core:jar:3.3.0.RELEASE:compile

 |  \- org.reactivestreams:reactive-streams:jar:1.0.3:compile

 +- io.projectreactor.addons:reactor-extra:jar:3.3.0.RELEASE:compile

 +- io.projectreactor:reactor-test:jar:3.3.2.RELEASE:test

 +- javax.interceptor:javax.interceptor-api:jar:1.2:compile

 +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.11.0:compile

 |  +- org.yaml:snakeyaml:jar:1.25:compile

 |  \- com.fasterxml.jackson.core:jackson-core:jar:2.11.0:compile

 +- com.squareup.okhttp3:mockwebserver:jar:3.8.1:test

 |  +- com.squareup.okhttp3:okhttp:jar:3.8.1:test

 |  |  \- com.squareup.okio:okio:jar:1.13.0:test

 |  +- org.bouncycastle:bcprov-jdk15on:jar:1.50:compile

 |  \- junit:junit:jar:4.12:test

 |     \- org.hamcrest:hamcrest-core:jar:2.1:test

 +- org.apache.commons:commons-lang3:jar:3.9:compile

 +- org.jetbrains.kotlin:kotlin-stdlib:jar:1.3.61:compile

 |  +- org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.3.61:compile

 |  \- org.jetbrains:annotations:jar:13.0:compile

 +- org.jetbrains.kotlin:kotlin-reflect:jar:1.3.61:compile

 \- org.jetbrains.kotlin:kotlin-test-junit:jar:1.3.61:test

    +- org.jetbrains.kotlin:kotlin-test-annotations-common:jar:1.3.61:test

    \- org.jetbrains.kotlin:kotlin-test:jar:1.3.61:test

       \- org.jetbrains.kotlin:kotlin-test-common:jar:1.3.61:test

It is a microservice using other microservices and exposing a reactive rest API. After I've added the security dependencies Tests do not run anymore, building context fails with the following error:

Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException:

Invalid bean definition with name 'conversionServicePostProcessor'

defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]:

Cannot register bean definition [Root bean: class [org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=conversionServicePostProcessor; initMethodName=null; destroyMethodName=(inferred);

defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]] for bean 'conversionServicePostProcessor':

There is already [Root bean: class [org.springframework.security.config.annotation.web.reactive.WebFluxSecurityConfiguration]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=conversionServicePostProcessor; initMethodName=null; destroyMethodName=(inferred);

defined in class path resource [org/springframework/security/config/annotation/web/reactive/WebFluxSecurityConfiguration.class]] bound.

How can I get rid of the error and use my reactive spring security?

I've tried to filter the WebSecurityConfiguration with the Component scan, setting the application type as reactive and removing all the dependencies I could - did not help.

0

There are 0 answers