最近在学习Spring,做了个简单的MultiActionController,在-servlet.xml的文件中没有配置HandlerMapping,所以默认使用DefaultAnnotationHandlerMapping。
写了个简单的例子:
@RequestMapping("/")
public String welcomeHandler() {
return "welcome";
}
在tomcat启动时,可以看到:
2011-6-23 19:08:46 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
信息: Root mapping to handler 'clinicController'
可见映射是成功的,可是访问http://localhost:8081/petclinic/,出现404错误。最后发现web.xml中,welcome-file-list 配置是:
<welcome-file-list>
</welcome-file-list>
中间加一行:
<welcome-file-list>
<welcome-file></welcome-file>
</welcome-file-list>
问题解决。