当我想访问我的网站时,出现以下错误:
The requested resource is not available.
我注意到问题出在
<mvc:resources mapping="/resources/**" location="../../resources/normalMode/"/>
行的mvc-dispatcher-servlet.xml文件中,但我不知道为什么?你有什么解决方案 ?
我的项目结构:
- src
- main
- java
- com
- myblog
- controller
-//all java files as controller
- resources
- normalMode
- css
- header.css
- webapp
- /WEB-INF
- /pages
- mvc-dispatcher.xml
- web.xml
mvc-dispatcher-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.myblog.controller" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property value="org.springframework.web.servlet.view.JstlView"
name="viewClass" />
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<mvc:resources mapping="/resources/**" location="../../resources/normalMode/"/>
</beans>
web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
IndexController.java
package com.myblog.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping(value={"","/","home"})
public class IndexController {
@RequestMapping(method=RequestMethod.GET)
public ModelAndView init(){
return new ModelAndView("index");
}
}
最佳答案
您需要添加
<mvc:annotation-driven/>
到您的
mvc-dispatcher-servlet.xml
。通过这种配置(和组件扫描),Spring将扫描并注册带有@Controller
注释的@RequestMapping
方法。使用您当前的配置,没有注册任何此类处理程序,因此没有任何内容可以处理您对
/
的请求。