작성
·
4K
0
강의 따라하면서 같이 코드 작성하고있었습니다!
이번강의에서 config를 할때 분명 @autowired랑 @repository @service를 삭제 하고 @bean으로 할당을 하였는데
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'helloController' method
hello.hellospring.controller.HelloController#helloApi(String)
to {GET /hello-string}: There is already 'helloController' bean method
hello.hellospring.controller.HelloController#helloString(String) mapped.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1794) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
at hello.hellospring.HelloSpringApplication.main(HelloSpringApplication.java:10) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.3.4.RELEASE.jar:2.3.4.RELEASE]
Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'helloController' method
hello.hellospring.controller.HelloController#helloApi(String)
to {GET /hello-string}: There is already 'helloController' bean method
hello.hellospring.controller.HelloController#helloString(String) mapped.
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.validateMethodMapping(AbstractHandlerMethodMapping.java:636) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.register(AbstractHandlerMethodMapping.java:603) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod(AbstractHandlerMethodMapping.java:318) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod(RequestMappingHandlerMapping.java:378) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod(RequestMappingHandlerMapping.java:75) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lambda$detectHandlerMethods$1(AbstractHandlerMethodMapping.java:288) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:723) ~[na:na]
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.detectHandlerMethods(AbstractHandlerMethodMapping.java:286) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.processCandidateBean(AbstractHandlerMethodMapping.java:258) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:217) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:205) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:189) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1790) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE]
... 22 common frames omitted
Process finished with exit code 0
이렇게 에러가뜹니다 ㅠㅠ 이미 bean이 존재한다고 에러가 뜨는 것 같습니다 ㅠㅠ
그래서 혹시몰라서 이번강의에서 config파일 삭제하고 이전강의까지의 코드 형태로다가 autowired랑 service기타등등을 다시 control+z로 되돌려서 다시 시행해보았는데 같은 에러가 뜹니다
답변 5
1
1
안녕하세요. DenBe님^^
오류 메시지를 보니 다음과 같은 부분이 보입니다.
hello.hellospring.controller.HelloController#helloApi(String)
to {GET /hello-string}: There is already 'helloController' bean method
hello.hellospring.controller.HelloController#helloString(String) mapped.
helloApi와 helloString이 둘다 /hello-string이라는 정보를 매핑하고 있는 것 같아요^^!
이 부분을 한번 확인해보시겠어요?
0
감사합니다! 왜 localhost:8080을 쳤을때 home.html이 아니라 static의 html파일이 열리는지는 모르겠지만 작동합니다!! ㅠㅠ 감사합니다:) 다음강의를 향해 달려가도록 하겠습니다~~~
0
안녕하세요. DenBe님
코드를 확인해보았습니다.
1. 순환참조 문제는 다음 링크를 확인해주세요^^ https://www.inflearn.com/questions/48156
2. 테스트 실패는 다음을 확인해주세요.
A. 테이블의 데이터를 모두 지우고 다시 시도해주세요.
B. 회원가입 다음 테스트가 실패하는데, 다음과 같이 변경해주세요.
이전 assertThat(member.getName()).isEqualTo(findMember);
변경 assertThat(member.getName()).isEqualTo(findMember.getName());
저는 이렇게 하니까 잘 동작하더라구요^^
0
앗 ㅎ.. bean설정에서 에러난줄알았는데 주소설정이 잘못되었었군요 ㅠㅠ 감사합니다
저 에러를 해결하고나 다른 에러들이 계속 따라옵니다 ㅠㅠ 저 에러 해결못하고 다음단계소스 계속 따라해서일까요 ㅠㅠ
이번엔 bean이 순환된다고 에러가 뜨네요 ㅠㅠ
지금 완강을 찍은 상태인데
test 했을때 중복검사? 하는 거기 테스트 계속해서 오류가나고..
거기다가 localhost:8080/
에 들어가면 계속 static 파일이 출력됩니다..
현재 일단 완강했습니다!!
( 너무나좋은강의 감사해요 ㅠㅠ 다른사이트에서 인강듣고 진짜 헤매다가 인프런 추천받아서 들었는데 진짜 살것같아요.. ㅎ 로드맵 쭉 따라가기로 했습니다. )
처음 에러 해결했을때는 갑자기 save와 join이 try catch로 바꿔야 한다하해서 요리조리 만져보다가..
그거해결했더니 지금 저러고 있어요 ㅠㅠ 혹시몰라 몇군데는 코드 복붙도 해봤는데 제가 어디서 놓쳤는지 모르겟어요
https://drive.google.com/file/d/17k51p5_xx_ErisC8AikWOvyzvh9V_MVY/view?usp=sharing
혹시몰라 zip파일 google drive 공유 링크도 올려봅니다 ㅠㅠ