每一个看似简单的社会现象其实都只露出了冰山一角。——林达
遇到这个报错,方案1:
在页面上添加:
1
| <link rel="icon" href="/static/favicon.ico">
|
前提是你有icon
并且放到了static
下面
方案2:
写个过滤器,给它过滤掉
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| package com.ruben.simplescaffold.filter;
import cn.hutool.core.lang.Opt; import cn.hutool.core.text.CharSequenceUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component;
import javax.servlet.*; import javax.servlet.annotation.WebFilter; import javax.servlet.http.HttpServletRequest; import java.io.IOException; import java.util.Arrays; import java.util.List;
@Slf4j @Component @WebFilter(filterName = "faviconFilter", urlPatterns = "/**") public class UserAgentFilter implements Filter {
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; String uri = httpRequest.getRequestURI(); if (uri.contains(FAVICON)) { response.getWriter().write(CharSequenceUtil.EMPTY); return; } chain.doFilter(request, response); } }
|
方案3:
写一个接口,返回空
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| package com.ruben.simplescaffold.controller;
import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody;
@Controller public class IndexController {
@GetMapping({"favicon.ico", "favicon"}) @ResponseBody public void favicon() { }
}
|