[Jenkins] java.lang.IllegalStateException: Cannot map handler 'xxxxController' to URL path [/xx/xxx]: There is already handler of type [class com.xx.xxx] mapped.

Article

[Jenkins] java.lang.IllegalStateException: Cannot map handler 'xxxxController' to URL path [/xx/xxx]: There is already handler of type [class com.xx.xxx] mapped.

- 이슈
기존에 사용하던 AController를 제거 후, BController를 생성하여 AController에서 사용했던 메서드 및 requestMapping 정보를 적용하여 jenkins를 통해 배포를 시도.
그러나 WAS 기동시 아래와 같이 Exception이 발생.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0' defined in file [/usr/local/tomcat7/webapps/ROOT/WEB-INF/classes/com/config/spring/dispatcher-servlet.xml]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: Cannot map handler 'xxxxController' to URL path [/x/xx/xxx/xxxx]: There is already handler of type [class com.xx.controller.xxxxController] mapped.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:605)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:926)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:477)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:638)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:595)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:652)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:514)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:455)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:138)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1230)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1174)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1066)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5393)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5691)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1017)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:993)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1127)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:2020)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:473)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:622)
at java.lang.Thread.run(Thread.java:748)


- 문제 원인
WAS에 배포된 ROOT 디렉토리의 classes 디렉토리를 찾아가보니 git repository에서는 삭제한 class 파일이 존재. ㅡ,.ㅡ;
jenkins의 build 폴더에 가서 확인해보니 여기에도 삭제했던 class파일이 존재.
결국 ROOT.war파일을 생성할 때에는 build 디렉토리의 build된 class 파일이 사용되는데 jenkins가 삭제된 파일을 초기화해주지는 않는구나...라는.... 


- 해결
1. mapping url이 서로 겹치지만 않아도 되는 경우라면, RequestMapping의 URL을 변경해준다.

2. 위 문제 원인을 해결하기 위해서는 jenkins의 해당 build job 디렉토리 > build 디렉토리 하위에 위치한, 삭제된 class파일이 실제 존재하는지 확인 후, 존재하면 삭제 후, jenkins build job 실행을 해줄 필요가 있다.

Dev Jinwon's Share
f
t