spring 注入静态变量 报错 no property

功能描述:
发送短信工具类:该工具类定义了静态发短信的方法,所有使用的用户名,密码都需要定义为静态,这里需要通过spring 读取配置文件注入

首先定义静态变量:
private static String host="";
private static String username="";
private static String password="";

下面是静态的发送短信的方法:
/**
* @param host
* @param username
* @param password
* @param SMSBean
* @return
*/
public static String [] sendSMS(SMSBean smsBean)
{

String smsContext;
HttpMethodBase method = null;
try
{
smsContext = URLEncoder.encode(smsBean.getContent(),"utf-8");

String Url = "http://www.kasms.net/Api/smssend.aspx?user=" + username
+ "&pass=" + password + "&telno=1&msg=" + smsContext
+ "&mobiles=" + smsBean.getSendmobile();
System.out.println(Url);
HttpClient client = new HttpClient();
method = new PostMethod(Url);
method.setRequestHeader("Content-Type","text/html; charset=utf-8");
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(3,false));

int result = client.executeMethod(method);
if(result != HttpStatus.SC_OK)
{
System.err.println("Method failed: " + method.getStatusLine());
return new String []{"1","连接失败"};
}

}
catch(HttpException e)
{
System.out.println("服务器异常,请检查短信发送协议是否正确!");
e.printStackTrace();
return new String []{"1","连接失败"};
}
catch(IOException e)
{
System.out.println("IO异常,系统将自动重发3次。如一直失败!请检查网络是否正常!");
e.printStackTrace();
return new String []{"1","连接失败"};
}
finally
{
method.releaseConnection();
}
return new String []{"0","短信发送成功"};
}


后面是通过spring注入bean的get,set方法
错误就在这里:

/**
* @return the host
*/
public static String getHost()
{
return host;
}

/**
* @param host the host to set
*/
public static void setHost(String host)
{
SMSTools.host = host;
}

这里和平时的一看就不同,没有研究源码,应该是spring在读get,set方法时没有识别出来!

改成
/**
* @return the host
*/
public String getHost()
{
return host;
}

/**
* @param host the host to set
*/
public void setHost(String host)
{
SMSTools.host = host;
}
确行了...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值