import org.apache.log4j.Logger;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import com.zenith.shuttle.jaxws.app.Settings;
import javax.annotation.PostConstruct;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
@Lazy(false)
@Service
public class SmsSettings {
public static final String CORG_CODE = "sms";
private String confRootPath;
private Properties properties;
private String corgName;
private String confCorgPath;
private String configFileName;
public SmsSettings() throws IOException {
this.corgName = CORG_CODE;
File rootFile = Settings.getPrefFolder();
if(rootFile==null){
Settings.setPrefFolder("src"+File.separator+"test"+File.separator+"resources"+File.separator);
}
confRootPath = Settings.getPrefFolder().getAbsolutePath()+File.separator;
confCorgPath = confRootPath+corgName+File.separator;
configFileName = corgName+".properties";
}
public String getConfRootPath(){
return confRootPath;
}
public Object get(String key) {
return properties.get(key);
}
public String getString(String key) {
return (String) properties.get(key);
}
@PostConstruct
public void init () {
File settingsFile = new File(confCorgPath+configFileName);
if(settingsFile.exists()){
properties = new Properties();
InputStream inputStream = null;
try{
inputStream = new FileInputStream(settingsFile);
properties.load(inputStream);
}catch (Exception e){
logger.error("配置加载初始化异常",e);
}finally {
if(inputStream!=null){
try {
inputStream.close();
}catch (Exception e){
logger.error("配置加载流关闭异常",e);
}
}
}
}
}
}
需要的jar包 maven 配置
<dependency>
<groupId>com.zenith.shuttle.components</groupId>
<artifactId>jaxws-ec</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>