Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SpringMVC:控制器映射工作,但返回404_Java_Spring_Spring Mvc_Mapping - Fatal编程技术网

Java SpringMVC:控制器映射工作,但返回404

Java SpringMVC:控制器映射工作,但返回404,java,spring,spring-mvc,mapping,Java,Spring,Spring Mvc,Mapping,我正在尝试创建一个SpringMVCWeb应用程序。以下是我的配置: web.xml 当我调试代码并尝试“/”或“/login”映射时,我看到调用了正确的方法,但是当我返回相应的字符串时,我得到了404错误 我的文件夹是这样组织的 webapp --META-INF/ ----MANIFEST.MF --WEB-INF/ ----Assets/ ------css/ ------img/ ------js/ ----Views/ ------index.html ------login.htm

我正在尝试创建一个SpringMVCWeb应用程序。以下是我的配置:

web.xml

当我调试代码并尝试“/”或“/login”映射时,我看到调用了正确的方法,但是当我返回相应的字符串时,我得到了404错误

我的文件夹是这样组织的

webapp
--META-INF/
----MANIFEST.MF
--WEB-INF/
----Assets/
------css/
------img/
------js/
----Views/
------index.html
------login.html
----dispatcher-servlet.xml
----web.xml
我哪里出错了


谢谢你的帮助

首先,您的
DispatcherServlet.xml
应该由
DispatcherServlet
加载,而不是由
ContextLoaderListener
加载。您还尝试加载了两次安全上下文。您是对的,将
DispatcherServlet.xml
声明移动到
DispatcherServlet
使其工作。谢谢
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <context:property-placeholder location="classpath*:bookstore.properties" />

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>WEB-INF/Views/</value>
        </property>
        <property name="suffix">
            <value>.html</value>
        </property>
    </bean>


    <mvc:resources mapping="/static/**" location="Assets"/>

    <mvc:default-servlet-handler/>


</beans>
@Controller
public class HomeController {

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index() {
        int a = 0;

        a += 1;
        return "index";
    }

    @RequestMapping(value = "login", method = RequestMethod.GET)
    public String login() {
        return "login";
    }
}
webapp
--META-INF/
----MANIFEST.MF
--WEB-INF/
----Assets/
------css/
------img/
------js/
----Views/
------index.html
------login.html
----dispatcher-servlet.xml
----web.xml