Skip to content

Commit

Permalink
- add: 新增启动扫描外部jar包,配置实例:nutz.scans.paths=lib/
Browse files Browse the repository at this point in the history
  • Loading branch information
wentao committed Apr 2, 2019
1 parent 60256a4 commit cbc1e9e
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions nutzboot-core/src/main/java/org/nutz/boot/NbApp.java
@@ -1,5 +1,6 @@
package org.nutz.boot;

import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
Expand Down Expand Up @@ -27,21 +28,19 @@
import org.nutz.boot.tools.PropDocReader;
import org.nutz.ioc.IocLoader;
import org.nutz.ioc.impl.NutIoc;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.AnnotationIocLoader;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.ioc.loader.combo.ComboIocLoader;
import org.nutz.lang.Lang;
import org.nutz.lang.Mirror;
import org.nutz.lang.Stopwatch;
import org.nutz.lang.Streams;
import org.nutz.lang.Strings;
import org.nutz.lang.*;
import org.nutz.lang.util.LifeCycle;
import org.nutz.log.Log;
import org.nutz.log.LogAdapter;
import org.nutz.log.Logs;
import org.nutz.mvc.Mvcs;
import org.nutz.mvc.annotation.IocBy;
import org.nutz.resource.Scans;
import org.nutz.resource.impl.JarResourceLocation;

/**
* NutzBoot的主体
Expand All @@ -61,6 +60,11 @@ public class NbApp extends Thread {
*/
protected String[] args;

/**
* 扫描外部jar包路径
*/
protected String scansPaths = "nutz.scans.paths";

/**
* 是否允许命令行下的 -Dxxx.xxx.xxx=转为配置参数
*/
Expand Down Expand Up @@ -264,6 +268,22 @@ public void prepare() throws Exception {
this.prepareConfigureLoader();
listeners.forEach((listener)->listener.whenPrepareConfigureLoader(this, EventType.after));

// 配置信息准备好后,进行外部jar包对象Scan
PropertiesProxy propertiesProxy = ctx.getConf();
if(propertiesProxy.containsKey(scansPaths)) {
log.debugf("has scansPaths...");
String scansPathsValue = propertiesProxy.get(scansPaths);
// 适配多路径
for (String path : scansPathsValue.split(";")) {
path = AppContext.getDefault().getBasePath() + File.separator + path;
log.debugf("scan path %s", path);
for (File jar : Files.ls(path, ".jar$", null)) {
log.infof("addResourceFile:%s", jar.getPath());
Scans.me().addResourceLocation(new JarResourceLocation(jar.getPath()));
}
}
}

// 创建IocLoader体系
listeners.forEach((listener)->listener.whenPrepareIocLoader(this, EventType.before));
prepareIocLoader();
Expand Down

0 comments on commit cbc1e9e

Please sign in to comment.