spring静态注入
2015-05-29 09:48
447 查看
本次尝试使用spring注入实例到静态类中,spring并不建议使用静态类,在语法上做了限制。虽然本次尝试可以成功注入,但并未真正使用。使用注解方法配制,以下是代码实现:
public class PushUtil {
@Autowired
private XingeApp xinge;
}
@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); }
}
相关文章推荐
- Struts2之自定义类型转换器
- Java web基础总结十之—— jsp EL表达式
- eclipse4.4的google protocol buffer的proto文件编辑器Protocol Buffer Editor安装
- update Yosemite ,prompt " * you need to install the legacy Java SE 6 Runtime"
- Java 数组基础
- JAVA与指针
- 华为2014机试样题1: 计票统计 java实现
- java中ListIterator和Iterator的区别
- eclipse 快捷键大全
- java线程同步原理及wait,notify的用法及与sleep的区别
- Eclipse设置、调优、使用
- java通过Annotation配置权限
- struts2 文件上传与下载原理
- eclipse内存溢出问题
- 用Spring TestContext 做带事务回滚的JUnit测试
- java 开发异常解决
- java 获取当前时间
- Java知多少(77)日期和时间类
- 【项目管理和构建】十分钟教程,eclipse配置maven + 创建maven项目(三)
- 【项目管理和构建】十分钟教程,eclipse配置maven + 创建maven项目(三)