1、去掉原有的@value注入,增加需要注入变量值得set方法package com.**.common.toolspublic class HttpUtil { // http请求超时时间(需要注入的值!!!) private static int maxTimeOut;/***主体代码忽略**/ public static HttpResponse post(){ /** *主体代码忽略 **/ HttpResponse response = null; RequestConfig config = RequestConfig.custom().setConnectTimeout(maxTimeOut); return response; } //增加set方法!!! public void setMaxTimeOut(int maxTimeOut) { HttpUtil.maxTimeOut = maxTimeOut; }}
2、spring-config-service增加bean实例化:
<bean id="httpUtil" class="com.**.tools.HttpUtil">
<property name="maxTimeOut" value="${post.try.maxtimeout}" />
</bean>
3、properties配置不改变,依然采用
# http请求超时时间
post.try.maxtimeout=20000