出现这个错误的原因:
Servlet-mapping映射模式中使用了/service/*,在Java 代码的controller中又加入了service前缀,实际上,不需要再加service前缀。
web.xml
<listener> <listener-class>ch.qos.logback.ext.spring.web.LogbackConfigListener</listener-class> </listener>
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
<!-- 定义DispatcherServlet,拦截请求 --> <servlet> <servlet-name>dispatch</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <!-- 映射Rest服务 --> <servlet-mapping> <servlet-name>dispatch</servlet-name> <url-pattern>/service/*</url-pattern> </servlet-mapping> |
LogViewController.java
@RestController @RequestMapping("api/ilogs/logview") public class LogViewController { public final static String PARAM_APPID = "appid"; public final static String PARAM_HOST = "host"; public final static String PARAM_NODE = "nodeid"; public final static String PARAM_LOGTIME_START = "logstarttime"; public final static String PARAM_LOGTIME_END = "logendtime";
public final static String PARAM_BASEDIR = "basedir";
String logFilesBaseDir = null;
@Autowired ILogFileView logFileview; //以下代码省略 |
解决办法:去掉controller类中的@RequesMapping()的前缀“service”,修改后的controller为:
LogViewController.java
@RestController @RequestMapping("ilogs/logview") public class LogViewController { public final static String PARAM_APPID = "appid"; public final static String PARAM_HOST = "host"; public final static String PARAM_NODE = "nodeid"; public final static String PARAM_LOGTIME_START = "logstarttime"; public final static String PARAM_LOGTIME_END = "logendtime";
public final static String PARAM_BASEDIR = "basedir";
String logFilesBaseDir = null;
@Autowired ILogFileView logFileview; //以下代码省略 |