Backend Language/Spring boot(Java)

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled / @RestController 이용 μ‹œ ERROR λ°œμƒ

chaerlo127 2021. 12. 2. 13:30
728x90

β€» ν•΄κ²° λ‚΄μš©μ€ 맨 λ§ˆμ§€λ§‰μ— 있음 β€» 

 

 

 

객체지ν–₯적사고와 ν”„λ‘œκ·Έλž˜λ° μˆ˜μ—…μ„ λ“£λ˜ 쀑 이와 같은 μ—λŸ¬κ°€ λ°œμƒν•˜μ˜€λ‹€.

 

κ΅μˆ˜λ‹˜μ΄ μ„€λͺ…ν•΄μ£Όμ‹  μ½”λ“œλ₯Ό λ˜‘κ°™μ΄ μž‘μ„±ν–ˆλŠ”λ°,

λ‚˜λ§Œ 이런 였λ₯˜κ°€ λ°œμƒν•œ 것이닀.

 

특히 @RestControllerλ₯Ό μ£Όμ„μ²˜λ¦¬ ν•΄μ œν•˜κ³ 

μ§„ν–‰ν–ˆλ”λ‹ˆ λ°œμƒν•œ 였λ₯˜μ˜€λ‹€,,,

( κ·Έ μ „μ—λŠ” 잘만 λλŠ”λ°,, μ™œκ·Έλ €,,)

 

였λ₯˜λ‚΄μš©μ€ λ‹€μŒκ³Ό κ°™λ‹€.

 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-12-02 13:15:47.039 ERROR 28612 --- [           main] o.s.boot.SpringApplication               : Application run failed

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 'application' method
com.example.PetAppMidterm.Application#feedDog(Long)
to {PUT [/pets/{petId}/feed]}: There is already 'application' bean method
com.example.PetAppMidterm.Application#feedCat(Long) mapped.
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.12.jar:5.3.12]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.12.jar:5.3.12]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.12.jar:5.3.12]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.12.jar:5.3.12]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.12.jar:5.3.12]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.12.jar:5.3.12]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.12.jar:5.3.12]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.12.jar:5.3.12]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.12.jar:5.3.12]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.12.jar:5.3.12]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.6.jar:2.5.6]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-2.5.6.jar:2.5.6]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-2.5.6.jar:2.5.6]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[spring-boot-2.5.6.jar:2.5.6]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-2.5.6.jar:2.5.6]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) ~[spring-boot-2.5.6.jar:2.5.6]
        at com.example.PetAppMidterm.Application.main(Application.java:31) ~[classes/:na]
Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'application' method
com.example.PetAppMidterm.Application#feedDog(Long)
to {PUT [/pets/{petId}/feed]}: There is already 'application' bean method
com.example.PetAppMidterm.Application#feedCat(Long) mapped.
        at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.validateMethodMapping(AbstractHandlerMethodMapping.java:669) ~[spring-webmvc-5.3.12.jar:5.3.12]
        at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.register(AbstractHandlerMethodMapping.java:635) ~[spring-webmvc-5.3.12.jar:5.3.12]
        at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod(AbstractHandlerMethodMapping.java:332) ~[spring-webmvc-5.3.12.jar:5.3.12]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod(RequestMappingHandlerMapping.java:395) ~[spring-webmvc-5.3.12.jar:5.3.12]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod(RequestMappingHandlerMapping.java:76) ~[spring-webmvc-5.3.12.jar:5.3.12]
        at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lambda$detectHandlerMethods$2(AbstractHandlerMethodMapping.java:299) ~[spring-webmvc-5.3.12.jar:5.3.12]
        at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:723) ~[na:na]
        at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.detectHandlerMethods(AbstractHandlerMethodMapping.java:297) ~[spring-webmvc-5.3.12.jar:5.3.12]
        at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.processCandidateBean(AbstractHandlerMethodMapping.java:266) ~[spring-webmvc-5.3.12.jar:5.3.12]
        at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:225) ~[spring-webmvc-5.3.12.jar:5.3.12]
        at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:213) ~[spring-webmvc-5.3.12.jar:5.3.12]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:206) ~[spring-webmvc-5.3.12.jar:5.3.12]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.12.jar:5.3.12]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.j800) ~[spring-beans-5.3.12.jar:5.3.12]
        ... 16 common frames omitted

 

 Cannot map 'application' method
com.example.PetAppMidterm.Application#feedDog(Long)
to {PUT [/pets/{petId}/feed]}: There is already 'application' bean method

 

 

μ—λŸ¬λ¬Έμ„ μ‚΄νŽ΄λ³΄λ©΄,

이와 같은 λ‚΄μš©μ΄ μžˆλ‹€.

 

μ½”λ“œλ₯Ό μ‚΄νŽ΄λ³΄λ‹ˆ, 

바보같이 같은 pathλ₯Ό μž‘μ„±ν•œ 것이 μ•„λ‹ˆκ² λŠ”κ°€.

 

 

 

//path 뢀뢄이 잘λͺ»λ˜μ–΄ 있던 κ²ƒμž„,,, 아무리 생각해도 μ™œ 같은 κ²ƒμœΌλ‘œ ν•  생각을 ν–ˆμ§€ λ°”λ³΄μž„

@RequestMapping(method = RequestMethod.PUT, path="cats/{petId}/feed")
	public String feedCat(@PathVariable(value = "petId") Long petId){


		return feed(petId);

	}

	@RequestMapping(method = RequestMethod.PUT, path="dogs/{petId}/feed")
	public String feedDog(@PathVariable(value = "petId") Long petId){


		return feed(petId);

	}

 

λ‹€μ‹œ λ³€κ²½ν•΄μ£Όλ‹ˆ 잘 λ˜λŠ” 것을 확인 ν•  수 μžˆλ‹€.

 

 

μ•„μ§κΉŒμ§€ μ—λŸ¬λ¬Έμ„ λ³΄λŠ” 것이 μ–΄λ ΅κ³ ,

ꡬ글링을 κ³„μ†ν•˜κ³  μžˆμ§€λ§Œ,

 

μ˜μ–΄μ™€ 코딩곡뢀λ₯Ό μ—΄μ‹¬νžˆν•΄μ„œ

μ—λŸ¬λ¬Έμ„ 잘 μž‘μ„ 수 μžˆλ„λ‘ λ…Έλ ₯ν•΄μ•Όκ² λ‹€.

728x90

 

728x90