创建maven项目,nutz版本1.r.63
src/main/resources/db.js
var ioc = {
// 读取配置文件
conf : {
type : "org.nutz.ioc.impl.PropertiesProxy",
fields : {
paths : [ "etc/" ]
}
},
dataSource : {
factory : "$conf#make",
args : [ "com.alibaba.druid.pool.DruidDataSource", "db." ],
type : "com.alibaba.druid.pool.DruidDataSource",
events : {
create : "init",
depose : 'close'
}
},
dao : {
type : "org.nutz.dao.impl.NutDao",
args : [ {refer : "dataSource" } ]
}
};
etc目录下有db.properties
db.driver=com.mysql.jdbc.Driver
db.url=jdbc:mysql://127.0.0.1/quickpoi?zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8
db.username=root
db.password=123456
IocMaster
package com.elvish.quickpoi.base.nutz;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.impl.NutIoc;
import org.nutz.ioc.loader.combo.ComboIocLoader;
import org.nutz.log.Log;
import org.nutz.log.Logs;
/**
* Ioc管理容器
*
* @author Elvish
*/
public class IocMaster {
private static final Log LOGGER = Logs.get();
private static Ioc ioc = null;
private IocMaster() {
}
public static Ioc getInstance() {
if (null != ioc) {
return ioc;
}
try {
ioc = new NutIoc(new ComboIocLoader("*js", ".", "*anno",
"com.elvish.quickpoi", "*tx"));
} catch (ClassNotFoundException e) {
String msg = "create ioc failed...";
LOGGER.error(msg);
LOGGER.error(e.getMessage());
throw new RuntimeException(e);
}
return ioc;
}
public static <T> T get(Class<T> clz) {
return getInstance().get(clz);
}
public static <T> T get(Class<T> clz, String name) {
return getInstance().get(clz, name);
}
}
日志
17-11-28 11:10:28.641 INFO [main] Select SystemLog as Nutz.Log implement
17-11-28 11:10:28.829 DEBUG [main] Locations count=20 time use 65ms
17-11-28 11:10:28.913 DEBUG [main] Found 0 resource by src( . ) , regex( ^(.+[.])(js|json)$ )
17-11-28 11:10:28.955 DEBUG [main] Using 95 castor for Castors
疑问
ioc = new NutIoc(new ComboIocLoader("*js", ".", "*anno","com.elvish.quickpoi", "*tx"));
上面代码中位置给错了??? 试过不用“.”,用“”也是同样找不到文件。