`
liudong_1985
  • 浏览: 35928 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

系统管理类--SystemEnvironmentManager

阅读更多
package com.mypack.core;

import java.io.IOException;
import java.util.Properties;

import javax.annotation.PostConstruct;

import org.springframework.core.io.Resource;
import org.springframework.util.Assert;

/**
 * 
 * 系统管理类
 * 
 * @author Administrator
 * 
 */
public class SystemEnvironmentManager {
	private static Properties systemEnvironmentConfigProperties = new Properties();

	private Resource resource;

	@PostConstruct
	public void init() {
		Assert.notNull(resource, "parameter resource is not null");

		readSystemEnvironmentConfigProperties();
	}

	private void readSystemEnvironmentConfigProperties() {

		try {
			systemEnvironmentConfigProperties.load(resource.getInputStream());
		} catch (IOException e) {

			throw new RuntimeException(e.getMessage(), e);

		}
	}

	public static String getProperty(String code) {
		if (code == null) {
			throw new IllegalArgumentException("parameter code is not null");
		}
		return systemEnvironmentConfigProperties.getProperty(code);
	}

	public Resource getResource() {
		return resource;
	}

	public void setResource(Resource resource) {
		this.resource = resource;
	}

}



<bean id="systemEnvironmentManager"
		class="com.mypack.core.SystemEnvironmentManager">
		<property name="resource"
			value="classpath:system_environment_config.properties">
		</property>
</bean>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics