mirror of
https://gitee.com/nutz/nutzboot.git
synced 2024-11-30 02:38:28 +08:00
update: NbApp实例本身也放入Ioc容器
This commit is contained in:
parent
265cec9c7c
commit
4323f8e042
@ -132,9 +132,12 @@ public class MainLauncher {
|
||||
* HeTaro(探路者,正在踩坑)
|
||||
* [zozoh](https://github.com/zozoh)(路过...)
|
||||
* [wendal](https://github.com)(到处挖坑)
|
||||
* 瞎折腾(添加了demo-maker的几个选项)
|
||||
* [瞎折腾](https://gitee.com/lx19990999)(添加了demo-maker的几个选项)
|
||||
* 还有您的名字哦,告知我们吧
|
||||
|
||||
## 采用NutzBoot的公司
|
||||
|
||||
请访问链接 [采用公司](https://github.com/nutzam/nutzboot/issues/62)
|
||||
## 文档
|
||||
|
||||
* [NutzBoot简介](doc/overview.md)
|
||||
|
@ -56,11 +56,6 @@ public class NbApp extends Thread {
|
||||
*/
|
||||
protected String[] args;
|
||||
|
||||
/**
|
||||
* 主启动器类,必须设置
|
||||
*/
|
||||
protected Class<?> mainClass;
|
||||
|
||||
/**
|
||||
* 是否允许命令行下的 -Dxxx.xxx.xxx=转为配置参数
|
||||
*/
|
||||
@ -94,6 +89,7 @@ public class NbApp extends Thread {
|
||||
* 创建一个NbApp,把调用本构造方法的类作为mainClass
|
||||
*/
|
||||
public NbApp() {
|
||||
ctx = AppContext.getDefault();
|
||||
StackTraceElement[] ts = Thread.currentThread().getStackTrace();
|
||||
if (ts.length > 2) {
|
||||
setMainClass(Lang.loadClassQuite(ts[2].getClassName()));
|
||||
@ -105,7 +101,21 @@ public class NbApp extends Thread {
|
||||
* @param mainClass 主启动类
|
||||
*/
|
||||
public NbApp(Class<?> mainClass) {
|
||||
this.mainClass = mainClass;
|
||||
ctx = AppContext.getDefault();
|
||||
setMainClass(mainClass);
|
||||
}
|
||||
|
||||
public NbApp(AppContext ctx) {
|
||||
this.ctx = ctx;
|
||||
StackTraceElement[] ts = Thread.currentThread().getStackTrace();
|
||||
if (ts.length > 2) {
|
||||
setMainClass(Lang.loadClassQuite(ts[2].getClassName()));
|
||||
}
|
||||
}
|
||||
|
||||
public NbApp(AppContext ctx, Class<?> mainClass) {
|
||||
this.ctx = ctx;
|
||||
setMainClass(mainClass);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -120,7 +130,7 @@ public class NbApp extends Thread {
|
||||
* 设置主启动类
|
||||
*/
|
||||
public NbApp setMainClass(Class<?> mainClass) {
|
||||
this.mainClass = mainClass;
|
||||
this.ctx.setMainClass(mainClass);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -178,8 +188,8 @@ public class NbApp extends Thread {
|
||||
|
||||
ctx.startServers();
|
||||
|
||||
if (mainClass.getAnnotation(IocBean.class) != null)
|
||||
ctx.getIoc().get(mainClass);
|
||||
if (ctx.getMainClass().getAnnotation(IocBean.class) != null)
|
||||
ctx.getIoc().get(ctx.getMainClass());
|
||||
|
||||
sw.stop();
|
||||
log.infof("NB started : %sms", sw.du());
|
||||
@ -230,11 +240,6 @@ public class NbApp extends Thread {
|
||||
}
|
||||
|
||||
public void prepareBasic() throws Exception {
|
||||
if (this.ctx == null) {
|
||||
ctx = AppContext.getDefault();
|
||||
}
|
||||
if (ctx.getMainClass() == null && mainClass != null)
|
||||
ctx.setMainClass(mainClass);
|
||||
// 检查ClassLoader的情况
|
||||
if (ctx.getClassLoader() == null)
|
||||
ctx.setClassLoader(NbApp.class.getClassLoader());
|
||||
@ -330,7 +335,8 @@ public class NbApp extends Thread {
|
||||
if (!ctx.ioc.has("appContext")){
|
||||
Ioc2 ioc2 = (Ioc2)ctx.getIoc();
|
||||
ioc2.getIocContext().save("app", "appContext", new ObjectProxy(ctx));
|
||||
ioc2.getIocContext().save("app", "conf", new ObjectProxy(ctx.getConfigureLoader().get()));
|
||||
ioc2.getIocContext().save("app", "conf", new ObjectProxy(ctx.getConf()));
|
||||
ioc2.getIocContext().save("app", "nbApp", new ObjectProxy(this));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user