我是 J2EE/Spring 的新手。
我正在开发一个 RESTful Spring 服务。控制器类有几个映射。我的应用程序中没有 web.xml 文件。
现在,我想在构建生成的 war 文件中显示 index.xml 文件。有没有办法可以输入 url http://localhost/healthcheck/version
,它将显示这个静态 index.html 文件。
编辑:我尝试使用
@Controller
@RequestMapping("/healthcheck")
public class HealthCheck {
@RequestMapping(value = "/version", method = RequestMethod.GET)
public String getVersion() throws Exception {
URL indexUrl = servletContext.getResource("/index.html");
System.out.println("url path : " + indexUrl.getPath());
return indexUrl.getPath();
}
}
但是,当我输入 时http://localhost/healthcheck/version
,我的日志中会收到以下 DEBUG 消息,
10:23:47.199 [http-bio-8080-exec-2] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /localhost/wcm-service/index.html
10:23:47.200 [http-bio-8080-exec-2] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Did not find handler method for [/localhost/wcm-service/index.html]
10:23:47.200 [http-bio-8080-exec-2] WARN o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/wcm-service/localhost/wcm-service/index.html] in DispatcherServlet with name 'wcm-service'
任何帮助将不胜感激。
谢谢