Backend/spring (Boot)

[error] conversionServicePostProcessor Bean 중복 오류

dddzr 2025. 2. 23. 18:21

🚨 conversionServicePostProcessor Bean 중복 오류

A bean with that name has already been defined in class path resource

Description: The bean 'conversionServicePostProcessor', defined in class path resource [org/springframework/security/config/annotation/web/reactive/WebFluxSecurityConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class] and overriding is disabled. Action: Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

 

🔥 오류 원인

 Spring Security에서 WebFluxSecurityConfigurationWebSecurityConfiguration이 동시에 로드되면서,
conversionServicePostProcessor Bean이 중복 등록되어 충돌하는 문제!

💡 즉, WebFlux(리액티브)와 MVC(블로킹)가 혼용되면서 충돌이 발생!

 

🛠 해결 방법

1️⃣  강제로 Bean 덮어쓰기 허용

💡 이 방법은 강제로 덮어쓰기 때문에, 충돌을 해결하는 근본적인 방법은 아님! 

 

📖 YAML 사용 시

spring:
  main:
    allow-bean-definition-overriding: true

 

📖 Properties 사용 시

spring.main.allow-bean-definition-overriding=true

 

 

2️⃣ 의존성 확인

pom.xml에서 spring-boot-starter-webspring-boot-starter-webflux가 함께 포함되었는지 확인

<dependencies>
    <!-- 🚨 WebFlux와 충돌 가능, 필요 없으면 제거! -->
    <!-- <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency> -->

    <!-- ✅ 일반 MVC(Spring Web) 사용 시 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <!-- ✅ Spring Security 추가 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
</dependencies>



3️⃣ Security 설정 확인 (Security Config)

@EnableWebSecurity(Spring MVC)와 @EnableWebFluxSecurity(Spring WebFlux)사용 확인. 둘다 import되어 있거나 환경에 맞지 않는 것 사용했는지 확인.

 

📖 MVC(Spring Web) 사용 시

@EnableWebSecurity
public class SecurityConfig {
    // Security 설정
}

 

📖 WebFlux 사용 시

@EnableWebFluxSecurity
public class SecurityConfig {
    // Security 설정
}