dao.js文件 (放在路径在com/test/包下)
var ioc = {
conf : {
type : "org.nutz.ioc.impl.PropertiesProxy",
fields : {
paths : ["conf/custom/"]
}
},
dataSource : {
type : "com.alibaba.druid.pool.DruidDataSource",
events : {
create : "init",
depose : 'close'
},
fields : {
url : {java:"$conf.get('db.url')"},
username : {java:"$conf.get('db.username')"},
password : {java:"$conf.get('db.password')"},
testWhileIdle : true,
validationQuery : {java:"$conf.get('db.validationQuery')"},
maxActive : {java:"$conf.get('db.maxActive')"},
filters : "mergeStat",
connectionProperties : "druid.stat.slowSqlMillis=2000"
}
},
dao : {
type : "org.nutz.dao.impl.NutDao",
args : [{refer:"dataSource"}]
}
};
main程序:
package com.test;
public class Test {
public static void main(String[] args) {
Ioc ioc = new NutIoc(new JsonLoader("com/test/dao.js"));
Dao dao = ioc.get(NutDao.class, "dao");
new Test().getUsers(dao);
}
public void getUsers(Dao dao){
List<User> user = dao.query(User.class, Cnd.where("name", "like", "user%"));
for(User ulist:user){
System.out.println(ulist.getName());
}
}
}
dao注入不报错,但是无法取得正确的数据库结果。
但是如果把dataSource里参数写死,程序可以查询出结果。
麻烦帮忙看看。