自己想做个简单的数据统计,不用web,调用ioc注入失败,请问应该如何处理
配置文件 dao.js
var ioc = {
conf : {
type : "org.nutz.ioc.impl.PropertiesProxy",
fields : {
paths : ["custom/"]
}
},
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"}]
}
};
db.properties
# db_local
db_local.url=jdbc:mysql://127.0.0.1:3306/work
db_local.username=root
db_local.password=
db_local.validationQuery=select 1
db_local.maxActive=50
db_local.testWhileIdle=true
db_local.filters=mergeStat
db_local.connectionProperties=druid.stat.slowSqlMillis=2000
db_local.defaultAutoCommit=true
代码:
public static Ioc ioc;
static {
ioc = new NutIoc(new JsonLoader("ioc/dao.js"));
}
public static void main(String[] args) {
Dao dao = ioc.get(NutDao.class, "dao");
System.out.println(Json.toJson(dao.query("asset", null)));
}
报错 信息:
2017-8-24 15:20:9.147 DEBUG [main] Found 1 resource by src( ioc/dao.js ) , regex( ^(.+[.])(js|json)$ )
2017-8-24 15:20:9.149 DEBUG [main] loading ioc js config from [dao.js]
2017-8-24 15:20:9.448 DEBUG [main] Using 95 castor for Castors
2017-8-24 15:20:9.458 DEBUG [main] Loaded 5 bean define from path=[ioc/dao.js] --> [dataSourceDxYufabu, dataSource, dao, conf, dao_dx_yufabu]
2017-8-24 15:20:9.462 INFO [main] NutIoc init begin ...
2017-8-24 15:20:9.469 INFO [main] ... NutIoc init complete
2017-8-24 15:20:9.474 DEBUG [main] Get 'dao'<class org.nutz.dao.impl.NutDao>
2017-8-24 15:20:9.481 DEBUG [main] Load AopConfigure for anno=org.nutz.ioc.aop.Aop by type=org.nutz.ioc.aop.config.impl.AnnotationAopConfigration
2017-8-24 15:20:9.482 DEBUG [main] >> Load definition name=dao
2017-8-24 15:20:9.493 DEBUG [main] Loading define for name=dao
2017-8-24 15:20:9.513 DEBUG [main] Found IocObject(dao) in JsonLoader(paths=[ioc/dao.js])
2017-8-24 15:20:9.513 DEBUG [main] >> Make...'dao'<class org.nutz.dao.impl.NutDao>
2017-8-24 15:20:9.562 DEBUG [main] Load class org.nutz.dao.impl.NutDao without AOP
2017-8-24 15:20:9.563 DEBUG [main] Save object 'dao' to [app]
2017-8-24 15:20:9.566 DEBUG [main] Get 'dataSource'<>
2017-8-24 15:20:9.566 DEBUG [main] >> Load definition name=dataSource
2017-8-24 15:20:9.567 DEBUG [main] Loading define for name=dataSource
2017-8-24 15:20:9.600 DEBUG [main] Found IocObject(dataSource) in JsonLoader(paths=[ioc/dao.js])
2017-8-24 15:20:9.600 DEBUG [main] >> Make...'dataSource'<>
2017-8-24 15:20:9.688 DEBUG [main] Load class com.alibaba.druid.pool.DruidDataSource without AOP
2017-8-24 15:20:9.688 DEBUG [main] Save object 'dataSource' to [app]
2017-8-24 15:20:9.704 DEBUG [main] Get 'conf'<>
2017-8-24 15:20:9.705 DEBUG [main] >> Load definition name=conf
2017-8-24 15:20:9.705 DEBUG [main] Loading define for name=conf
2017-8-24 15:20:9.723 DEBUG [main] Found IocObject(conf) in JsonLoader(paths=[ioc/dao.js])
2017-8-24 15:20:9.724 DEBUG [main] >> Make...'conf'<>
2017-8-24 15:20:9.727 DEBUG [main] Load class org.nutz.ioc.impl.PropertiesProxy without AOP
2017-8-24 15:20:9.728 DEBUG [main] Save object 'conf' to [app]
2017-8-24 15:20:9.822 DEBUG [main] Found 1 resource by src( custom/ ) , regex( ^.+[.]properties$ )
2017-8-24 15:20:10.43 DEBUG [main] Remove object 'dataSource' from [app]
2017-8-24 15:20:10.43 DEBUG [main] Remove object 'dao' from [app]
Exception in thread "main" org.nutz.ioc.IocException: [dao, dataSource] # FAIL to create Ioc Bean name=[dataSource]
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:149)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:75)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
at demo.hello.MainSetup.main(MainSetup.java:32)
Caused by: java.lang.NullPointerException
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:559)
at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:642)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.nutz.ioc.trigger.MethodEventTrigger.trigger(MethodEventTrigger.java:18)
at org.nutz.ioc.weaver.DefaultWeaver.onCreate(DefaultWeaver.java:72)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
... 6 more