开发者社区 问答 正文

Spring 路径报错?报错

警告: No mapping found for HTTP request with URI [/] in DispatcherServlet with name 'appServlet'



@Controller
public class FirstController {
	/**
	 * 网站首页
	 * 
	 * @return
	 */
	@RequestMapping(value = "/",method =RequestMethod.GET)
	public String homePage() {

		return "index";
	}
	
	@RequestMapping(value = "/hello",method =RequestMethod.GET)
	@ResponseBody
	public String hello() {
		return "index";
	}
}

配置文件



<context:annotation-config />
	<mvc:annotation-driven />
	<context:component-scan base-package="com.whuboy.test" />
	<!-- Handles HTTP GET requests for /resources/** by efficiently serving 
		up static resources in the ${webappRoot}/resources/ directory -->
	<resources mapping="/resources/**" location="/resources/" />
	<!-- Resolves views selected for rendering by @Controllers to .jsp resources 
		in the /WEB-INF/views directory -->
	<beans:bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<beans:property name="prefix" value="/WEB-INF/view/" />
		<beans:property name="suffix" value=".jsp" />
	</beans:bean>




展开
收起
爱吃鱼的程序员 2020-06-14 16:36:55 448 分享 版权
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    appServlet的url-pattern是什么回复<aclass='referer'target='_blank'>@TheDreamwork:改成/呢?<url-pattern>/</url-pattern>

    <context:component-scan<spanstyle="font-family:Consolas,'BitstreamVeraSansMono','CourierNew',Courier,monospace;font-size:14px;line-height:15.3999996185303px;background-color:#FFFFFF;">base-package="com.whuboy.test."<spanstyle="font-family:Consolas,'BitstreamVeraSansMono','CourierNew',Courier,monospace;font-size:14px;line-height:15.3999996185303px;background-color:#FFFFFF;">/>

    或者

    <context:component-scan<spanstyle="font-family:Consolas,'BitstreamVeraSansMono','CourierNew',Courier,monospace;font-size:14px;line-height:15.3999996185303px;background-color:#FFFFFF;"> base-package="com.whuboy.*"<spanstyle="font-family:Consolas,'BitstreamVeraSansMono','CourierNew',Courier,monospace;font-size:14px;line-height:15.3999996185303px;background-color:#FFFFFF;"> />

    一样的,没效果

    楼主,这是什么配置文件啊?web.xml还是applicationContext.xml?

    <divclass='ref'>

    引用来自“simlegate”的评论

    楼主,这是什么配置文件啊?web.xml还是applicationContext.xml?

    请求报错是 <spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">appServlet 这个,但是controller里面没看到这个啊??是我看错了??不要只用斜杠,后面加点什么东西。回复<aclass='referer'target='_blank'>@TheDreamwork:把method=RequestMethod.GET去掉貌似无效。。

    你是怎么启动Spring的?

    eclipse直接runserver

    2020-06-14 16:37:11
    赞同 展开评论