【发布时间】:2021-09-28 16:30:35
【问题描述】:
我有以下控制器
@Controller
public class MyController {
@GetMapping({"/", "/{name}"})
public String hello(@PathVariable(required = false) String name) {
System.out.println("Name: " + name);
return "hello";
}
}
还有这个目录结构
- resources
- static
- favicon.ico
- templates
- hello.html
当我通过浏览器GET http://localhost:8080/ 时,我的应用程序打印:
Name: null
Name: favicon.ico
所以/favicon.ico 的请求被我的控制器捕获,但我希望 Spring 处理此请求并返回放置在此处的 favicon.ico resources/static/favicon.ico
我认为应该有一种不需要添加几行配置的方法。
【问题讨论】:
-
只是为了确保 - 包含 favicon.ico 的资源目录的路径是 src/main/resources/... ,对吗?
-
谢谢@AjayKumar 通过将 放入我的 html 头部来解决它,顺便说一句我将 favicon 移动到 src/main/resources/static/images/
标签: spring spring-boot favicon