Java Http状态代码404 spring mvc
我是SpringMVC的新手,我只是在尝试一个基本的例子。但是我收到了HTTPStats404错误。我的档案如下: 这是一个maven项目 /Web Inf/spring-mvc-demo-servlet.xmlJava Http状态代码404 spring mvc,java,spring,spring-mvc,Java,Spring,Spring Mvc,我是SpringMVC的新手,我只是在尝试一个基本的例子。但是我收到了HTTPStats404错误。我的档案如下: 这是一个maven项目 /Web Inf/spring-mvc-demo-servlet.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/200
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- Step 3: Add support for component scanning -->
<context:component-scan base-package="springdemo" />
<!-- Step 4: Add support for conversion, formatting and validation support -->
<mvc:annotation-driven/>
<!-- Step 5: Define Spring MVC view resolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
我正在EclipseIDE中创建一个动态Web项目,它是一个Maven项目,我试图运行它的服务器是Tomcat8.0.44
有人能帮我消除这个错误吗?因为您的servlet名称是web.xml中的dispatcher。spring将尝试加载名为dispatcher-servlet.xml的配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- Step 3: Add support for component scanning -->
<context:component-scan base-package="springdemo" />
<!-- Step 4: Add support for conversion, formatting and validation support -->
<mvc:annotation-driven/>
<!-- Step 5: Define Spring MVC view resolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
在dispatcher-servlet.xml中,必须提供组件扫描
我发现spring-mvc-demo-servlet.xml中的包名与控制器所在的包不匹配 spring-mvc-demo-servlet.xml:-
<context:component-scan base-package="springdemo" />
您的示例看起来没有正确的xsd版本,可能是由于jar文件版本 最好试试这个例子
您的
springmvc演示servlet.xml
与web.xml
相同,对吗?请发布您的spring mvc demo servlet.xml
@Rosii Robinson我更改了文件..错误地上传了相同的文件。现在它是正确的。检查组件扫描。您正在扫描packagecom.luv2code.springdemo
,然后您的控制器似乎也错误地位于springdemo
中。。。我正在跟踪一个演示,所以即使包名正确,它仍然会给出相同的错误。您正在调用什么URL
?但是param init和param value呢。这不会找到正确的XML吗?它应该找到。按照Anil的建议添加组件扫描
package springmvcdemo;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
@Component
public class HomeController {
@RequestMapping("/")
public String startPage(){
return "main-page";
}
}
<context:component-scan base-package="springdemo" />
package springmvcdemo;