Spring 弹簧注释HandlerMapping不工作
我不熟悉使用带注释控制器的spring控制器 这是我的配置 Bean定义Spring 弹簧注释HandlerMapping不工作,spring,spring-mvc,Spring,Spring Mvc,我不熟悉使用带注释控制器的spring控制器 这是我的配置 Bean定义 <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /> 尝试访问给定URL时,Spring抛出警告org.springframework.web.servlet.PageNotFound-在名为“springapp”的DispatcherServlet中找不到URI为
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
尝试访问给定URL时,Spring抛出警告org.springframework.web.servlet.PageNotFound-在名为“springapp”的DispatcherServlet中找不到URI为[/Learn/annotation/first.ftl]的HTTP请求的映射。我想您缺少的是组件扫描
<context:component-scan base-package="learn.web.controller" />
将此添加到您的配置中,然后重试
这将从指定的包加载所有带注释的组件
您的配置可能如下所示
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="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/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="learn.web.controller" />
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="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/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="learn.web.controller" />
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
</beans>