Backend/spring

[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์—์„œ WebFluxSecurityConfiguration๊ณผ WebSecurityConfiguration์ด ๋™์‹œ์— ๋กœ๋“œ๋˜๋ฉด์„œ,
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-web๊ณผ spring-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 ์„ค์ •
}