-
Oct 23rd, 2011, 09:24 PM
#1
Cannot map handler... There is already handler..mapped
Hi,
I am new here, can you please help me,
The controller is :
[ code]
@Controller
public class ViewAllBooksController
{
@Autowired // (you can use @Resource as well)
private BookService bookService;
public void setBookService(BookService bookService) {
this.bookService = bookService;
}
@RequestMapping("/viewAllBooks")
public ModelAndView viewAllBooks()
{
List<Book> allBooks = bookService.getEntireCatalogue();
return new ModelAndView("displayAllBooks", "allBooks", allBooks);
}
}
[/code ]
Dispatche-servlet.xml :
[ code]
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns
="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schem...-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<import resource="/application.xml"/>
<bean name="/viewAllBooks.do"
class="com.virtualpairprogrammers.control.ViewAllB ooksController">
<property name="bookService" ref="bookService"/>
</bean>
<context:component-scan base-package="com.virtualpairprogrammers"/>
</beans>
[/code ]
when I deployed I got this :
[ code]
SEVERE: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean wit
h name 'org.springframework.web.servlet.mvc.annotation.De faultAnnotationHandlerM
apping': Initialization of bean failed; nested exception is java.lang.IllegalSta
teException: Cannot map handler [viewAllBooksController] to URL path [/viewAllBo
oks]: There is already handler [com.virtualpairprogrammers.control.ViewAllBooksC
ontroller@402af3] mapped.
at org.springframework.beans.factory.support.Abstract AutowireCapableBean
Factory.doCreateBean(AbstractAutowireCapableBeanFa ctory.java:527)
at org.springframework.beans.factory.support.Abstract AutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFact ory.java:456)
at org.springframework.beans.factory.support.Abstract AutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFact ory.java:286)
at org.springframework.web.servlet.DispatcherServlet. createDefaultStrate
gy(DispatcherServlet.java:682)
at org.springframework.web.servlet.DispatcherServlet. getDefaultStrategie
s(DispatcherServlet.java:651)
at org.springframework.web.servlet.DispatcherServlet. initHandlerMappings
(DispatcherServlet.java:444)
at org.springframework.web.servlet.DispatcherServlet. initStrategies(Disp
atcherServlet.java:339)
at org.springframework.web.servlet.DispatcherServlet. onRefresh(Dispatche
rServlet.java:328)
at org.springframework.web.servlet.FrameworkServlet.o nApplicationEvent(F
rameworkServlet.java:523)
at org.springframework.web.servlet.FrameworkServlet$C ontextRefreshListen
er.onApplicationEvent(FrameworkServlet.java:749)
at org.springframework.web.servlet.FrameworkServlet$C ontextRefreshListen
er.onApplicationEvent(FrameworkServlet.java:1)
at org.springframework.context.event.GenericApplicati onListenerAdapter.o
nApplicationEvent(GenericApplicationListenerAdapte r.java:51)
at org.springframework.context.event.SourceFilteringL istener.onApplicati
onEventInternal(SourceFilteringListener.java:97)
at org.springframework.context.event.SourceFilteringL istener.onApplicati
onEvent(SourceFilteringListener.java:68)
at org.springframework.context.event.SimpleApplicatio nEventMulticaster.m
ulticastEvent(SimpleApplicationEventMulticaster.ja va:97)
at org.springframework.context.support.AbstractApplic ationContext.publis
hEvent(AbstractApplicationContext.java:303)
at org.springframework.context.support.AbstractApplic ationContext.finish
Refresh(AbstractApplicationContext.java:911)
at org.springframework.context.support.AbstractApplic ationContext.refres
h(AbstractApplicationContext.java:428)
at org.springframework.web.servlet.FrameworkServlet.c reateWebApplication
Context(FrameworkServlet.java:442)
at org.springframework.web.servlet.FrameworkServlet.c reateWebApplication
Context(FrameworkServlet.java:458)
at org.springframework.web.servlet.FrameworkServlet.i nitWebApplicationCo
ntext(FrameworkServlet.java:339)
at org.springframework.web.servlet.FrameworkServlet.i nitServletBean(Fram
eworkServlet.java:306)
at org.springframework.web.servlet.HttpServletBean.in it(HttpServletBean.
java:127)
at javax.servlet.GenericServlet.init(GenericServlet.j ava:212)
at org.apache.catalina.core.StandardWrapper.loadServl et(StandardWrapper.
java:1173)
at org.apache.catalina.core.StandardWrapper.load(Stan dardWrapper.java:99
3)
at org.apache.catalina.core.StandardContext.loadOnSta rtup(StandardContex
t.java:4149)
at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4
458)
at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase
.java:791)
at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:77
1)
at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:526)
at org.apache.catalina.startup.HostConfig.deployWAR(H ostConfig.java:850)
at org.apache.catalina.startup.HostConfig.deployWARs( HostConfig.java:724
)
at org.apache.catalina.startup.HostConfig.deployApps( HostConfig.java:493
)
at org.apache.catalina.startup.HostConfig.start(HostC onfig.java:1206)
at org.apache.catalina.startup.HostConfig.lifecycleEv ent(HostConfig.java
:314)
at org.apache.catalina.util.LifecycleSupport.fireLife cycleEvent(Lifecycl
eSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:722)
at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:443
)
at org.apache.catalina.core.StandardService.start(Sta ndardService.java:5
16)
at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:710
)
at org.apache.catalina.startup.Catalina.start(Catalin a.java:583)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:413)
Caused by: java.lang.IllegalStateException: Cannot map handler [viewAllBooksCont
roller] to URL path [/viewAllBooks]: There is already handler [com.virtualpairpr
ogrammers.control.ViewAllBooksController@402af3] mapped.
at org.springframework.web.servlet.handler.AbstractUr lHandlerMapping.reg
isterHandler(AbstractUrlHandlerMapping.java:390)
at org.springframework.web.servlet.handler.AbstractUr lHandlerMapping.reg
isterHandler(AbstractUrlHandlerMapping.java:362)
at org.springframework.web.servlet.handler.AbstractDe tectingUrlHandlerMa
pping.detectHandlers(AbstractDetectingUrlHandlerMa pping.java:82)
at org.springframework.web.servlet.handler.AbstractDe tectingUrlHandlerMa
pping.initApplicationContext(AbstractDetectingUrlH andlerMapping.java:58)
at org.springframework.context.support.ApplicationObj ectSupport.initAppl
icationContext(ApplicationObjectSupport.java:119)
at org.springframework.web.context.support.WebApplica tionObjectSupport.i
nitApplicationContext(WebApplicationObjectSupport. java:72)
at org.springframework.context.support.ApplicationObj ectSupport.setAppli
cationContext(ApplicationObjectSupport.java:73)
at org.springframework.context.support.ApplicationCon textAwareProcessor.
invokeAwareInterfaces(ApplicationContextAwareProce ssor.java:106)
at org.springframework.context.support.ApplicationCon textAwareProcessor.
postProcessBeforeInitialization(ApplicationContext AwareProcessor.java:85)
at org.springframework.beans.factory.support.Abstract AutowireCapableBean
Factory.applyBeanPostProcessorsBeforeInitializatio n(AbstractAutowireCapableBeanF
actory.java:394)
at org.springframework.beans.factory.support.Abstract AutowireCapableBean
Factory.initializeBean(AbstractAutowireCapableBean Factory.java:1405)
at org.springframework.beans.factory.support.Abstract AutowireCapableBean
Factory.doCreateBean(AbstractAutowireCapableBeanFa ctory.java:519)
... 49 more
Oct 23, 2011 10:22:23 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /mywebapp threw load() exception
java.lang.IllegalStateException: Cannot map handler [viewAllBooksController] to
URL path [/viewAllBooks]: There is already handler [com.virtualpairprogrammers.c
ontrol.ViewAllBooksController@402af3] mapped.
[/code ]
Your help is appreciated.
Last edited by mlotfi; Oct 24th, 2011 at 07:24 AM.
-
Oct 23rd, 2011, 11:48 PM
#2
as first hand information i can see an extra space in the controller name. try removing that
<bean name="/viewAllBooks.do"
class="com.virtualpairprogrammers.control.ViewAllB ooksController">
<property name="bookService" ref="bookService"/>
</bean>
-
Oct 24th, 2011, 05:45 AM
#3
There is no space, just cut and paste from eclipse to here created this space.
-
Oct 24th, 2011, 05:58 AM
#4
Please use [ code][/code ] tags when posting code
... That way it remains readable..
I suggest you take a look at the logging when the server starts.
You will then notice that there is a BeanNameHandlerMapping which first maps the bean to the url (because it uses the name/id to map it) after that the DefautlAnnotationHandlerMapping will try to map the controller but there is already an existing mapping.
Next to that you have 2 instances of your controller.
1) Created by the definition in xml
2) Created by component scanning
either remove the xml or component-scanning
Finally judging from your configuration you probably have 4 instances of your controller because I suspect you also have a ContextLoaderListener which probably loads (part) of the same configuration the DispatcherServlet is loading.
-
Oct 24th, 2011, 06:00 AM
#5
can you post your complete dispatcher servlet using code tags. that makes it more readable.
-
Oct 24th, 2011, 08:34 AM
#6
Hi,
I'm the writer of the course the OP is following and I just wanted to let you know that we've received a support call about this and we're now working with him on solving the problem.
I think Marten is on the money, but I'll have a full look at his project code to check.
Thanks for all of your help on this thread, and I'm sorry that I'm the indirect cause of it!
(edited because my earlier post indicated it was a minor fault with web.xml, but I hadn't read the stacktrace properly).
Last edited by RichK; Oct 24th, 2011 at 09:18 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules