项目基于Spring
须要的依赖为:
<dependency>
<groupId>org.mitre.dsmiley.httpproxy</groupId>
<artifactId>smiley-http-proxy-servlet</artifactId>
<version>1.7</version>
</dependency>
只需要添加一个java文件即可,原理有待继续研究
package *.*.*.*;
import org.mitre.dsmiley.httpproxy.ProxyServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Created by czz on 2018/11/13.
*/
@Configuration
public class SolrProxyServletConfiguration {
@Bean
public ServletRegistrationBean servletRegistrationBean(){
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new ProxyServlet(), "/s/*");
servletRegistrationBean.addInitParameter("targetUri", "http://www.baidu.com/s");
servletRegistrationBean.addInitParameter(ProxyServlet.P_LOG, "false");
return servletRegistrationBean;
}
}
参考文章:Spring boot使用ProxyFilter进行服务代理
原文地址:https://www.cnblogs.com/czz-hl/p/9953903.html
时间: 2024-10-07 12:58:26