@SpringBootApplication
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
@EnableTransactionManagement
public class SvcServerApplication {
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(SvcServerApplication.class);
springApplication.addListeners(new SvcListeners());
springApplication.run(args);
// 测试main方法注入bean,项目中不要执行,注释掉
// TestService testService = ApplicationContextHelper.getBean(TestService.class);
// testService.testMain(10);
}
}
//监听器
public class SvcListeners implements ApplicationListener {
@Override
public void onApplicationEvent(ApplicationStartedEvent e) {
Environment environment = ApplicationContextHelper.applicationContext.getEnvironment();
try {
// magpie启动监听
new BootStrap().start(environment.getProperty("magpie.path"));
// 全渠道sdk装配
SDKConfig.getConfig().loadPropertiesFromPath(environment.getProperty("acp.sdk.properties.path"));
String smsTag = environment.getProperty("smsConnect");
if ("1".equals(smsTag)) {
// 生产环境初始化短信客户端,开启短信发送功能;测试环境关闭短信功能
UPMMClient.init(new SmsListener(), true);
}
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
// 启动A B Cache 内存块更新内存常用业务参数
DualBlockCache.getInstance().start(environment.getProperty("cardBin.dir"));
// TODO: 2018/8/16 上线时给logback-spring.xml中的46行 <appender-ref ref="STDOUT" /> 打上注释,关闭日志控制台输出
// 项目启动后加载配置文件参数进内存
PropertyUtils.loadProps();
}
}
//定时器任务
public void start(String cardBinDir) {
// 根据卡bin构建Darts
try {
// 读文件,装配list
Timestamp start = new Timestamp(System.currentTimeMillis());
logger.info("根据卡bin构建Darts,任务开始");
BufferedReader reader = new BufferedReader(new FileReader(cardBinDir));
String line;
// words 存储 cardBin
List<String> words = new ArrayList<>();
while ((line = reader.readLine()) != null) {
words.add(line.substring(0, line.indexOf(",")));
cardBinList.add(line);
}
reader.close();
logger.info("cardBin字典词条: " + words.size());
//定时器任务2
/**
* 将配置文件所有属性值读入内存,项目运行时不再读文件
*/
public static void loadProps() {
Properties prop = new Properties();
InputStream in = null;
try {
Environment environment = ApplicationContextHelper.applicationContext.getEnvironment();
in = new BufferedInputStream(new FileInputStream(environment.getProperty("conf.file.path")));
//prop.load(in);
prop.load(new InputStreamReader(in, "utf-8"));
if (prop.containsKey("workerId") && prop.containsKey("datacenterId")
&& prop.containsKey("orderIdMachineCode") && prop.containsKey("passiveBackUrl")
&& prop.containsKey("addnOpUrl")) {