【LSP】springboot过滤器禁止ip频繁访问

呸友   ·   发表于 4个月前   ·   编程代码

.编写一个过滤器:

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
@WebFilter(urlPatterns="/dyflight/*")
public class IpFilter implements Filter{

}
  

3.iputil

import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class IPUtil {

4配置

springboot启动类中添加过滤器和监听器的包扫描

@ServletComponentScan(basePackages="cn.xxx.common")
  

spring web.xml

过滤器

ipFilter com.xxxx.common.filter.IpFilter ipFilter /dyflight/**   
监听器:

com.xxxx.common.Listener.MyApplicationListener
0 Reply   |  Until 4个月前 | 5006 View
LoginCan Publish Content