RequestMappingHandler - 没有找到处理程序方法,为index.jsp

时间:2016-11-27 01:05:25

标签: java spring-mvc embedded-jetty jetty-9

我正在创建一个带有嵌入式Jetty Server的Spring webapp - 9.3.9。我的服务器正常启动没有任何错误,但是我在接收JSP页面时收到404。我使用此处给出的示例配置了JSP支持 - Embedded Jetty JSP。打开Debug Spring Debug我看到:

JstlView DEBUG - Forwarding to resource [/WEB-INF/views/index.jsp] in InternalResourceView 'index'
DispatcherServlet DEBUG - DispatcherServlet with name 'appServlet' processing GET request for [/webui/WEB-INF/views/index.jsp]
RequestMappingHandlerMapping DEBUG - Looking up handler method for path /WEB-INF/views/index.jsp
RequestMappingHandlerMapping DEBUG - Did not find handler method for [/WEB-INF/views/index.jsp]
SimpleUrlHandlerMapping DEBUG - Matching patterns for request [/WEB-INF/views/index.jsp] are [/**]
SimpleUrlHandlerMapping DEBUG - URI Template variables for request [/WEB-INF/views/index.jsp] are {}
SimpleUrlHandlerMapping DEBUG - Mapping [/WEB-INF/views/index.jsp] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/resources/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@113cc14d]]] and 1 interceptor
DispatcherServlet DEBUG - Last-Modified value for [/webui/WEB-INF/views/index.jsp] is: -1
DispatcherServlet DEBUG - DispatcherServlet with name 'appServlet' processing GET request for [/webui/error]
RequestMappingHandlerMapping DEBUG - Looking up handler method for path /error

不确定我收到的原因:

  

没找到[/WEB-INF/views/index.jsp]的处理程序方法

我有一个不同的项目来启动Jetty服务器,我的Spring Webapp部署在另一个项目上。

我的项目设置如下:

jetty-startup
   -src/main/java
    - ServerStart.java
    ...

webproject
   - src/main/java
     - Package com.admin.controllers
       - BaseController
   - src
     - main
       - webapp
         - META-INF
         - WEB-INF
           - web.xml
           - spring
             - appservlet
               - servlet-context.xml
           - views
             - index.jsp
             ..all other JSPs Here

调试时,我可以看到控制器命中代码,但是DispatcherServlet无法解析视图

我的BaseController.java是:

@Controller
public class BaseController {
  @RequestMapping("/login")
    public @ResponseBody String login() {
        System.out.println("Inside BaseController");

        Map<String, String> model = new HashMap<String, Object>(); 
        model.put("index", "hello Spring");          
        return new ModelAndView("index", model);
    }
}

我的web.xml是:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:log4j.xml</param-value>
  </context-param>
  <servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextClass</param-name>
      <param-value>com.admin.tools.webapp.contexts.XmlValidatorContext</param-value>
    </init-param>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <servlet>
    <servlet-name>wsServlet</servlet-name>
    <servlet-class>com.admin.tools.webapp.servlets.webSocketServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
  </servlet>
 <servlet-mapping>
    <servlet-name>wsServlet</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping> 


 </web-app>

我的Servlet-context.xml如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">

<annotation-driven />

<beans:bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
        <beans:property name="order" value="0" />
    </beans:bean>   
<context:component-scan base-package="com.admin.tools.webapp.controllers />

不确定,我正在制作什么配置错误。当我启动服务器并转到URL http://localhost:8080/login时,我可以看到系统从家庭控制器出来但收到404 - 问题访问/webapp/WEB-INF/views/404.jsp

非常感谢任何建议。谢谢!

0 个答案:

没有答案