读书人

替Web应用设置代理访问(Spring)

发布时间: 2012-10-07 17:28:51 作者: rapoo

为Web应用设置代理访问(Spring)

如果开发过程中涉及的开发环境需要通过代理服务器才能访问外网的数据库资源或外网的网络资源,该如何处理呢?

?

此处所涉及的web应用使用到Spring,因此实现Spring的ContextLoaderListener类,然后覆盖其createContextLoader函数,如下:

 @Override protected ContextLoader createContextLoader() {     Properties prop = System.getProperties();      //数据库需要使用Socket代理      prop.setProperty("socksProxyHost", "192.168.0.26");      prop.setProperty("socksProxyPort", "1080");      //网络资源使用Http代理      prop.put("proxySet","true");        prop.put("proxyHost","192.168.0.26");        prop.put("proxyPort","808");       return super.createContextLoader(); }

?

这样就可以通过代理的方式访问啦,最后请别忘记在Web.xml中配置好这个上下文监听器!

?

?

读书人网 >Web前端

热点推荐