我正在尝试在spring mvc中使用MultiActionController,但我在日志中继续获得404以及以下消息
(org.springframework.web.servlet.PageNotFound) 找不到HTTP请求的映射 URI [/www.mysite.no/a/b/c] in DispatcherServlet,名称为“myServlet”
看起来我正在关注这本书的例子,但它仍然不起作用?想法,任何人?
代码示例:web.xml
<servlet-mapping>
<servlet-name>subscriptionServlet</servlet-name>
<url-pattern>/a/b/*</url-pattern>
</servlet-mapping>
Spring config:my-servlet.xml
<beans ...>
<bean id="myController" class="foo.bar.MyController">
<property name="methodNameResolver" ref="productMethodNameResolver"/>
</bean>
<bean id="productMethodNameResolver" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
<property name="mappings">
<value>
/*=view
</value>
</property>
</bean>
</beans>
控制器:
public class MyController extends MultiActionController {
Log logger = ...
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception{
logger.fatal("Never displayed in log");
return super.handleRequest(request, response);
}
public ModelAndView view(HttpServletRequest request, HttpServletResponse response) throws Exception {
logger.fatal("Never displayed in log");
return null;
}
答案 0 :(得分:0)
我已将url映射到控制器中的方法,但缺少url映射到实际控制器。必须将以下内容添加到spring config
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>
/*=myController
</value>
</property>
</bean>