SpringMVC controller 无法访问

Eric-A 2016-12-03 07:31:15
项目是SpringMVC Maven结构的
index.jsp 页面可以正常访问,访问controller的 地址却一直是404,各路大神 帮忙看下。。。
controller访问地址:http://localhost:8080/clt/larw/verify?signature=signature×tamp=timestamp&nonce=nonce&echostr=echostr
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/spring-root.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>


spring-root.xml 现在是个空文件

spring-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<!-- 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/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>

<!-- Only needed because we install custom converters to support the examples in the org.springframewok.samples.mvc.convert package -->
<!-- <beans:bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<beans:property name="formatters">
<beans:bean class="org.springframework.samples.mvc.convert.MaskFormatAnnotationFormatterFactory" />
</beans:property>
</beans:bean> -->

<!-- Only needed because we require fileupload in the org.springframework.samples.mvc.fileupload package -->
<!-- beans:bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" /> -->

<!-- Imports user-defined @Controller beans that process client requests -->
<beans:import resource="spring-controllers.xml" />

<!-- <task:annotation-driven /> -->

</beans:beans>


spring-controllers.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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
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-3.0.xsd">

<!-- Maps '/' requests to the 'home' view -->
<mvc:view-controller path="/" view-name="index"/>

<mvc:annotation-driven />

<context:component-scan base-package="org.clt.controller" />

<!-- <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> -->
</beans>


test controller
package org.clt.controller;

import org.clt.service.WechatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/larw")
public class WechatListener {

@Autowired
private WechatService wechatService;

@RequestMapping(value="/verify", method=RequestMethod.GET)
public String verification(@RequestParam String signature,@RequestParam String timestamp,
@RequestParam String nonce, @RequestParam String echostr) {
System.out.println("-----------------come in WechatListener-----------------");

String result = null;
Boolean flag = wechatService.verifyWechatConfig(signature, timestamp, nonce);

return flag ? echostr : result;
}
}


...全文
352 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
原因是web module读取Service module 有问题。。。 请问这个什么意思啊???求解答,入门小白跟视频学这儿controller这里已经卡了好几天了
LHuiMail 2016-12-05
  • 打赏
  • 举报
回复
No mapping found for HTTP request with URI [/clt/larw/verify] in DispatcherServlet with name 'default-dispatcher' 控制台有没有这条信息?
Eric-A 2016-12-05
  • 打赏
  • 举报
回复
谢谢大家,问题已经解决了,原因是web module读取Service module 有问题。。。
Eric-A 2016-12-03
  • 打赏
  • 举报
回复
引用 5 楼 wangjian223344 的回复:
目前没看出来什么问题,但是你可以用简单的方式,试出来 比如@RequestMapping(value="larw//verify", method=RequestMethod.POST). 把这个@RequestMapping("/larw")去掉 @RequestParam String signature,@RequestParam String timestamp, @RequestParam String nonce, @RequestParam String echostr 参数用对象的方式传 verifyWechatConfig 这个是验证签证是否合法的吧 怎么名字叫什么config 名字取的不好
我把class上的RequestMapping去掉了,只在method上加上了RequestMapping,依然404.。。。
魔都 2016-12-03
  • 打赏
  • 举报
回复
目前没看出来什么问题,但是你可以用简单的方式,试出来 比如@RequestMapping(value="larw//verify", method=RequestMethod.POST). 把这个@RequestMapping("/larw")去掉 @RequestParam String signature,@RequestParam String timestamp, @RequestParam String nonce, @RequestParam String echostr 参数用对象的方式传 verifyWechatConfig 这个是验证签证是否合法的吧 怎么名字叫什么config 名字取的不好
Eric-A 2016-12-03
  • 打赏
  • 举报
回复
引用 3 楼 m2200 的回复:
你项目启动成功了么?
成功了 index页面可以访问 直接访问controller就报404
爱睡觉的阿狸 2016-12-03
  • 打赏
  • 举报
回复
你项目启动成功了么?
Eric-A 2016-12-03
  • 打赏
  • 举报
回复
引用 1 楼 dotnetstudio 的回复:
你在后台的java工程写个测试类,对WeChatListener的verification进行测试,看能否打印出那些信息。
org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8080/clt/larw/verify": Connection refused; nested exception is java.net.ConnectException: Connection refused junit test结果
KeepSayingNo 2016-12-03
  • 打赏
  • 举报
回复
你在后台的java工程写个测试类,对WeChatListener的verification进行测试,看能否打印出那些信息。

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧