spring静态注入

本次尝试使用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);
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值