Java org.springframework.web.servlet.DispatcherServlet noHandlerFound
访问Java org.springframework.web.servlet.DispatcherServlet noHandlerFound,java,spring,tomcat,Java,Spring,Tomcat,访问http://api:8080/users我和哪个404在控制台中出现此错误: 2014年9月23日下午5:57:52 org.springframework.web.servlet.DispatcherServlet noHandlerFound 警告:在名为“dispatcher”的DispatcherServlet中找不到URI为[/users]的HTTP请求的映射 当我访问http://localhost:8080/api/users我的浏览器中有404,但控制台中没有错误 appl
http://api:8080/users
我和哪个404在控制台中出现此错误:
2014年9月23日下午5:57:52 org.springframework.web.servlet.DispatcherServlet noHandlerFound
警告:在名为“dispatcher”的DispatcherServlet中找不到URI为[/users]的HTTP请求的映射
当我访问http://localhost:8080/api/users
我的浏览器中有404,但控制台中没有错误
applicationContext.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:p="http://www.springframework.org/schema/p"
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/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.api"/>
</beans>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
Note: property prefix and suffix need to modify based on your application like .jsp if you are using jsp files.
如果有人有任何线索,我将不胜感激。我查了几个错误与我得到的相同的问题,但常见的解决办法是添加我已经添加的,所以我不知道还有什么要做。谢谢
编辑:我刚刚将所有代码更新为最新的参考文档,但仍然得到相同的错误。
编辑:更新以显示文件的当前状态。将web.xml更改为
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
调度员
org.springframework.web.servlet.DispatcherServlet
2.
调度员
/
并将-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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.api"/>
</beans>
运行代码不需要applicationContext.xml需要在spring-context.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:p="http://www.springframework.org/schema/p"
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/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.api"/>
</beans>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
Note: property prefix and suffix need to modify based on your application like .jsp if you are using jsp files.
注意:如果您使用的是jsp文件,则需要根据您的应用程序修改属性前缀和后缀,如.jsp。
一个常见的错误是
确保pom.xml中的组id是中提到的组id的父级
</context:component-scan>
其结果是在maven构建和配置中找不到控制器
因此,映射没有完成到正确的jsp。原因-此问题背后的主要原因是servlet.xml文件无法找到可以重定向请求的适当控制器 解决方案-确保几件事:
我也面临同样的问题
org.springframework.web.servlet.DispatcherServlet noHandlerFound
为了解决这个问题,我在《邮递员》中点击了不同的url。花了一整天的时间,我才知道解决方法,只要检查一下你的邮递员你点击了哪个url就可以了。 当您创建maven项目时,默认情况下它不会在“javaResource/src/main”下创建“java”文件夹,这是获取控制器路径所必需的 确保首先在“javaResource/src/main”中创建java文件夹,然后创建包和控制器 附上截图供参考
我刚刚检查了
servlet.xml
文件并解决了问题:
<context:component-scan base-package="com.YOURHOST" />
以下是我是如何摆脱这一困境的,以及我做错了什么 在使用web原型创建maven项目时,我们在main下没有java目录。您必须手动创建它,并在其下添加一个目录。此目录是servlet.xml需要的基本包 servlet.xml和附加的基本包映像的位置,以供参考
在从一个项目复制到另一个项目时,我遇到了类似的问题。我没有添加index.jsp
添加此项解决了我的问题。希望有帮助。在maven中,没有创建“java”文件夹。我创建了src/main/java,解决了这个问题 这也是jyot在这篇文章中提出的。
阅读Spring参考文档,您将旧配置与Spring MVC的新配置混合在一起。你的代码是错误的。你能说得更具体一点吗?我已经用参考文档中的最新代码更新了我的问题,但我仍然得到相同的错误。现在你的配置是正确的。URL
http://api:8080/
没有意义,要测试的URL必须是http://localhost:8080/CONTEXTROOT/users
其中CONTEXTROOT
可在您选择的项目中使用右键单击->属性->Web项目设置
。如果您的项目已经部署在Tomcat中,那么URL必须是http://localhost:8080/projectname/users
我已经这样做了,但是我仍然得到了404,但是我的控制台中没有错误。我尝试了,但是我必须添加:为了让它工作,但是我仍然在Java类用户中得到相同的错误,你需要在类上有@Controller注释(你在编辑之前有过它)。我尝试过使用@Controller和不使用@Controller,或者你得到的是noHandlerFound异常还是404错误?如果是404,那是因为控制器不返回任何对象或模型。我在eclipse控制台中找不到Handler,但在浏览器中找不到404请正确格式化您的代码,以便OP可以确定什么是注释,什么是代码。谢谢,我遇到了同样的问题,现在您帮助我解决了。谢谢。我创建了这个类,它最终被保存在参考资料文件夹中。
<context:component-scan base- package="com.cavesofprogramming.spring.web.controllers">
<context:component-scan base-package="com.YOURHOST" />