프로그래밍/JAVA\Spring

[Spring] class 이름 중복으로 인한 오류

J200302 2022. 1. 12. 18:24

패캠의 spring 강의를 듣는 도중 오류발생

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.example.hello.HelloApplication]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'apiController' for bean class [com.example.hello.reponse.controller.ApiController] conflicts with existing, non-compatible bean definition of same name and class [com.example.hello.getAPI.controller.ApiController]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:189) ~[spring-context-5.3.14.jar:5.3.14]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331) ~[spring-context-5.3.14.jar:5.3.14]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:247) ~[spring-context-5.3.14.jar:5.3.14]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311) ~[spring-context-5.3.14.jar:5.3.14]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:112) ~[spring-context-5.3.14.jar:5.3.14]
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746) ~[spring-context-5.3.14.jar:5.3.14]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564) ~[spring-context-5.3.14.jar:5.3.14]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.2.jar:2.6.2]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[spring-boot-2.6.2.jar:2.6.2]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) ~[spring-boot-2.6.2.jar:2.6.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[spring-boot-2.6.2.jar:2.6.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.2.jar:2.6.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) ~[spring-boot-2.6.2.jar:2.6.2]
	at com.example.hello.HelloApplication.main(HelloApplication.java:10) ~[main/:na]
Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'apiController' for bean class [com.example.hello.reponse.controller.ApiController] conflicts with existing, non-compatible bean definition of same name and class [com.example.hello.getAPI.controller.ApiController]
	at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.checkCandidate(ClassPathBeanDefinitionScanner.java:349) ~[spring-context-5.3.14.jar:5.3.14]
	at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:287) ~[spring-context-5.3.14.jar:5.3.14]
	at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:128) ~[spring-context-5.3.14.jar:5.3.14]
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:296) ~[spring-context-5.3.14.jar:5.3.14]
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:250) ~[spring-context-5.3.14.jar:5.3.14]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:207) ~[spring-context-5.3.14.jar:5.3.14]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:175) ~[spring-context-5.3.14.jar:5.3.14]
	... 13 common frames omitted

강의랑 코드를 비교해봐도 틀린게 없어 오류메세지를 상펴보니,,

*

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class....

Annotation-specified bean name 'apiController' for bean class [com.example.hello.reponse.controller.ApiController] conflicts with existing, non-compatible bean definition of same name and class [com.example.hello.getAPI.controller.ApiController]

 

클래스 내임이 중복되서 bean생성이 안됐던것

강의에서는 hello하위 패키지에 해당하는 것들을 모두 새로운 프로젝트를 생성해가며 설명했기때문에 

하나의 프로젝트에서 패키지를 나눠가면 공부한결과 나온 오류였다.

 

수정

class명 수정으로 간단하게 해결!!