Skip to content

Commit

Permalink
spring配置文件加载目录设置
Browse files Browse the repository at this point in the history
  • Loading branch information
qq254963746 committed Feb 16, 2016
1 parent fbd87f7 commit b994563
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.lts.startup;

import com.lts.tasktracker.TaskTracker;

import org.springframework.context.ApplicationContext;

/**
Expand All @@ -10,13 +9,23 @@
public class SpringStartup {

@SuppressWarnings("resource")
public static TaskTracker start(String cfgPath) {
public static TaskTracker start(TaskTrackerCfg cfg, String cfgPath) {

System.setProperty("lts.tasktracker.cfg.path", cfgPath);

ApplicationContext context = new LTSXmlApplicationContext(
new String[]{"classpath*:spring/*.xml"}
);
String[] springXmlPaths = cfg.getSpringXmlPaths();

String[] paths;

if (springXmlPaths != null) {
paths = new String[springXmlPaths.length + 1];
paths[0] = "classpath:spring/lts-startup.xml";
System.arraycopy(springXmlPaths, 0, paths, 1, springXmlPaths.length);
} else {
paths = new String[]{"classpath*:spring/*.xml"};
}

ApplicationContext context = new LTSXmlApplicationContext(paths);
return (TaskTracker) context.getBean("ltsTaskTracker");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class TaskTrackerCfg {

private boolean useSpring = false;

private String[] springXmlPaths;

private Map<String, String> configs;

public String getRegistryAddress() {
Expand Down Expand Up @@ -101,4 +103,12 @@ public Class getJobRunnerClass() {
public void setJobRunnerClass(Class jobRunnerClass) {
this.jobRunnerClass = jobRunnerClass;
}

public String[] getSpringXmlPaths() {
return springXmlPaths;
}

public void setSpringXmlPaths(String[] springXmlPaths) {
this.springXmlPaths = springXmlPaths;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ public static TaskTrackerCfg load(String confPath) throws CfgException {
cfg.setBizLoggerLevel(Level.valueOf(bizLoggerLevel));
}

String springXmlPaths = conf.getProperty("springXmlPaths");
if (StringUtils.isNotEmpty(springXmlPaths)) {
// 都好分割
String[] tmpArr = springXmlPaths.split(",");
if (tmpArr.length > 0) {
String[] springXmlPathArr = new String[tmpArr.length];
for (int i = 0; i < tmpArr.length; i++) {
springXmlPathArr[i] = StringUtils.trim(tmpArr[i]);
}
cfg.setSpringXmlPaths(springXmlPathArr);
}
}

Map<String, String> configs = new HashMap<String, String>();
for (Map.Entry<Object, Object> entry : conf.entrySet()) {
String key = entry.getKey().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class TaskTrackerStartup {

public static void main(String[] args) {
String cfgPath = args[0];
// String cfgPath = "/Users/hugui/Data/Workspace/github/light-task-scheduler/lts-startup/lts-startup-tasktracker/src/main/resources/conf";
start(cfgPath);
}

Expand All @@ -20,7 +19,7 @@ public static void start(String cfgPath) {
final TaskTracker taskTracker;

if (cfg.isUseSpring()) {
taskTracker = SpringStartup.start(cfgPath);
taskTracker = SpringStartup.start(cfg, cfgPath);
} else {
taskTracker = DefaultStartup.start(cfg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ configs.job.fail.store=leveldb
# 使用TaskTracker使用Spring,使用的话也要自己引入Spring相关jar
useSpring=false

# 配置 spring配置文件路径,用逗号隔开,如: classpath*:spring/*.xml
springXmlPaths=


Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.lts.startup;

import org.junit.Test;

import static org.junit.Assert.*;

/**
* Created by hugui.hg on 2/16/16.
*/
public class TaskTrackerStartupTest {

@Test
public void testMain() throws Exception {
TaskTrackerStartup.main(new String[]{"/Users/hugui/Data/Workspace/github/light-task-scheduler/lts-startup/lts-startup-tasktracker/src/main/resources/conf"});
}
}
4 changes: 3 additions & 1 deletion 开发计划.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@
主要是为了去除对zkClient和curator的依赖
####7.LTS nio框架的实现
主要是为了去除对netty和mina的依赖(群主正在开发中)
####8.任务依赖的原生支持
####8.任务依赖的原生支持
####9.对任务业务日志的处理
可以采用按数量分表

0 comments on commit b994563

Please sign in to comment.