Code Bye

spring mvc @RequestMapping("/flow_statistic.jspx")注解报错

 

各位大侠,本人之前使用spring mvc 的@RequestMapping,采用的是路径配置方式,例如:@RequestMapping(“/hello”),一直没有问题。今天在查看其他人写的项目时,采用的是@RequestMapping(“/flow_statistic.jspx”),我在spring 配置文件中自动扫描注解,如:
<!– 控制器所在的包{添加注解的} –>
<context:component-scan base-package=”com.jeecms.cms.action.front” />

在项目启动时,报错:如下:
Java HotSpot(TM) Client VM warning: MaxNewSize (262144k) is equal to or greater than the entire heap (262144k).  A new generation size of 262080k will be used.
2014-7-23 0:41:35 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property “”debug”” to “”0″” did not find a matching property.
2014-7-23 0:41:35 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: E:\Java\jdk6\bin;E:\kaifa_gongju\tomcat-6.0.18\bin
2014-7-23 0:41:35 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-80
2014-7-23 0:41:35 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 672 ms
2014-7-23 0:41:35 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2014-7-23 0:41:35 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.18
2014-7-23 0:41:38 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
2014-7-23 0:42:07 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring FrameworkServlet “”JeeCmsAdmin””
2014-7-23 0:42:17 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring FrameworkServlet “”JeeCmsFront””
00:42:20.140 ERROR org.springframework.web.servlet.DispatcherServlet – Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name “”org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0″” defined in ServletContext resource [/WEB-INF/config/jeecms-servlet-front.xml]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: Cannot map handler “”siteFlowAct”” to URL path [/flow_statistic.jspx]: There is already handler of type [class com.jeecms.cms.action.front.CmsSiteFlowAct] mapped.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527) ~[spring.beans-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) ~[spring.beans-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) ~[spring.beans-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring.beans-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) ~[spring.beans-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring.beans-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:398) ~[spring.beans-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1146) ~[spring.context-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:275) ~[spring.beans-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.initHandlerMappings(DispatcherServlet.java:424) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.initStrategies(DispatcherServlet.java:339) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.onRefresh(DispatcherServlet.java:328) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.onApplicationEvent(FrameworkServlet.java:523) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet$ContextRefreshListener.onApplicationEvent(FrameworkServlet.java:749) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet$ContextRefreshListener.onApplicationEvent(FrameworkServlet.java:1) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.context.event.GenericApplicationListenerAdapter.onApplicationEvent(GenericApplicationListenerAdapter.java:51) ~[spring.context-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.context.event.SourceFilteringListener.onApplicationEventInternal(SourceFilteringListener.java:97) ~[spring.context-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.context.event.SourceFilteringListener.onApplicationEvent(SourceFilteringListener.java:68) ~[spring.context-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97) ~[spring.context-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:303) ~[spring.context-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:911) ~[spring.context-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:428) ~[spring.context-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127) [spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at javax.servlet.GenericServlet.init(GenericServlet.java:241) [javaee.jar:9.0]
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172) [catalina.jar:na]
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992) [catalina.jar:na]
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058) [catalina.jar:na]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371) [catalina.jar:na]
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) [catalina.jar:na]
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719) [catalina.jar:na]
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) [catalina.jar:na]
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) [catalina.jar:na]
at org.apache.catalina.core.StandardService.start(StandardService.java:516) [catalina.jar:na]
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710) [catalina.jar:na]
at org.apache.catalina.startup.Catalina.start(Catalina.java:578) [catalina.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_24]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_24]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_24]
at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_24]
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288) [bootstrap.jar:na]
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413) [bootstrap.jar:na]
Caused by: java.lang.IllegalStateException: Cannot map handler “”siteFlowAct”” to URL path [/flow_statistic.jspx]: There is already handler of type [class com.jeecms.cms.action.front.CmsSiteFlowAct] mapped.
at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:390) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:362) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping.detectHandlers(AbstractDetectingUrlHandlerMapping.java:82) ~[spring.web.servlet-3.0.5.jar:3.0.5.RELEASE]
at 

这种情况本人没有碰到过,百度了下,也没有找到答案。所以请大家帮我看看。谢谢!
有意思的是去掉 自动扫描,就没问题了。
<!– 控制器所在的包{添加注解的} –>
<context:component-scan base-package=”com.jeecms.cms.action.front” />
不知道其中的原因。


37分
你这个Controller不只一个实例, 我猜你在spring主配置文件中也扫描到了这个Controller,那个地方不要扫描控制器。
<!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入 -->
	<context:component-scan base-package="com.xxx.xxx" use-default-filters="false" >
		<!-- 扫描符合 @Repository @Service的类 -->
		<context:include-filter type="annotation"
			expression="org.springframework.stereotype.Repository" />
		<context:include-filter type="annotation"
			expression="org.springframework.stereotype.Service" />
		<context:include-filter type="annotation"
			expression="org.springframework.stereotype.Component" />
		<context:exclude-filter type="annotation"
			expression="org.springframework.stereotype.Controller" />
	</context:component-scan>

然后在springMVC的xml中扫描Controller,就是你去掉掉的那句话

<!-- 自动扫描且只扫描@Controller -->
	<context:component-scan base-package="com.xxx.xxx" use-default-filters="false">
		<context:include-filter type="annotation"
			expression="org.springframework.stereotype.Controller" />
	</context:component-scan>

3分
/flow_statistic.jspx这个URL 在这里已经用了吧!there is already handler of type [class com.jeecms.cms.action.front.CmsSiteFlowAct] mapped.

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明spring mvc @RequestMapping("/flow_statistic.jspx")注解报错