Java SpringMVC:控制器映射工作,但返回404
我正在尝试创建一个SpringMVCWeb应用程序。以下是我的配置: web.xml 当我调试代码并尝试“/”或“/login”映射时,我看到调用了正确的方法,但是当我返回相应的字符串时,我得到了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
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