spring自动重载

本文通过一个Java示例展示了如何使用HttpClient POST方式发送请求到一个特定URL,并设置Cookie头来触发Spring Context的刷新操作。该示例还包含了对应Action类中实现Context刷新的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.运行类
public static void main(String[] args) {
String url = "http://127.0.0.1:8080/reload.action";
HttpClient client = new DefaultHttpClient();
HttpMethod method = getPostMethod();//使用POST方式提交数据
HttpUriRequest m=new HttpPost(url);
m.setHeader("Cookie","ceshi3.com=*****");
HttpResponse response;
try {
response=client.execute(m);
System.out.println(response.getEntity().getContent().read()+"---"+response.getStatusLine());
} catch (IOException e) {
e.printStackTrace();
}
//打印服务器返回的状态
System.out.println(method.getStatusLine());
method.releaseConnection();
}

2.action
  public String reload() {
WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(request.getSession()
.getServletContext());

if (context.getParent() != null) {
((AbstractRefreshableApplicationContext) context.getParent()).refresh();
}

((AbstractRefreshableApplicationContext) context).refresh();
System.out.println("--------Spring Context Reload----------------");
return null;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值