您的位置:首页 > 编程语言 > Java开发

spring静态注入

2015-05-29 09:48 447 查看
本次尝试使用spring注入实例到静态类中,spring并不建议使用静态类,在语法上做了限制。虽然本次尝试可以成功注入,但并未真正使用。使用注解方法配制,以下是代码实现:

@Service


public class PushUtil {

@Autowired

private XingeApp xinge;

private static PushUtil pushService;

public void setUserInfo(XingeApp xinge)

{
this.xinge = xinge;
}

@PostConstruct
public void init()

{

pushService = this;
pushService.xinge = this.xinge;

}

// 单个设备下发透传消息
public static JSONObject pushSingleDeviceMessage(String token, Message message) {
return pushService.xinge.pushSingleDevice(token, message);
}

// 单个设备下发通知消息
public static JSONObject demoPushSingleDeviceNotification(String token, Message message) {
JSONObject ret = pushService.xinge.pushSingleDevice(token, message);
return (ret);
}

// 单个设备下发通知消息
public static JSONObject demoPushSingleDeviceIOS(String token, MessageIOS message) {
return pushService.xinge.pushSingleDevice(token, message, XingeApp.IOSENV_DEV);
}

// 单个设备下发通知Intent
// setIntent()的内容需要使用intent.toUri(Intent.URI_INTENT_SCHEME)方法来得到序列化后的Intent(自定义参数也包含在Intent内)
// 终端收到后可通过intent.parseUri()来反序列化得到Intent
public static JSONObject demoPushSingleDeviceNotificationIntent(String token, Message message) {
JSONObject ret = pushService.xinge.pushSingleDevice(token, message);
return (ret);
}

// 下发单个账号
public static JSONObject demoPushSingleAccount(int deviceType, String account, Message message) {
JSONObject ret = pushService.xinge.pushSingleAccount(deviceType, account, message);
return (ret);
}

// 下发多个账号
public static JSONObject demoPushAccountList(List<String> accountList, Message message) {
return pushService.xinge.pushAccountList(0, accountList, message);
}


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring-静态注