spring注解注入加载系统配置

/**
 * 系统配置
 */
package com.daqsoft.common.web;

import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;

import com.daqsoft.common.util.XmlConvertUtils;
import com.daqsoft.hibernate.domain.TSysConfig;
import com.daqsoft.service.SysconfigService;

/**
 * @author jack.li
 * 
 */
public class Sysconfig {

	@Autowired
	private SysconfigService sysconfigService;
	public void setSysconfigService(SysconfigService sysconfigService) {
		this.sysconfigService = sysconfigService;
	}
	private static Sysconfig sysconfig;

	@PostConstruct
	public void init() {
		sysconfig = this;
		sysconfig.sysconfigService = this.sysconfigService;
	}

	public static String get(String key) {
		TSysConfig config = sysconfig.sysconfigService.get(1);
		Map<String, String> map = XmlConvertUtils.xmltoMap(config.getConfig());
		return map.get(key);
	}
	
	public static int getInt(String key) {
		TSysConfig config = sysconfig.sysconfigService.get(1);
		Map<String, String> map = XmlConvertUtils.xmltoMap(config.getConfig());
		return Integer.parseInt(map.get(key));
	}
	
	public static Map<String, Object> getAll() {
		TSysConfig config = sysconfig.sysconfigService.get(1);
		return XmlConvertUtils.xmltoMap(config.getConfig());
	}

}

你可能感兴趣的:(spring注解)