POM文件:
<!-- nutz -->
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutz</artifactId>
<version>1.r.65<ersion>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.10</ version>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</ version>
<scope>runtime</scope>
</dependency>
调用程序:
Ioc ioc = new NutIoc(new JsonLoader("/conf/ioc/ dao.js"));
DataSource ds = ioc.get(DataSource.class);
报错:
Exception in thread "main" org.nutz.ioc.IocException: IocBean[dataSource] throw Exception when creating
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:152)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:240)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:270)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:160)
at cn.tba.pojo.Person.main(Person.java:62)
Caused by: org.nutz.lang.born.BorningException: Fail to born or cast to 'javax.sql.DataSource'
by args: []
because: No suitable Constructor or Factory Method!!
at org.nutz.lang.Mirror.getBorning(Mirror.java:967)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:102)
... 4 more
若调用程序改为:
Ioc ioc = new NutIoc(new JsonLoader("/conf/ioc/dao.js"));
DataSource ds = ioc.get(DruidDataSource.class);
报错为:
Exception in thread "main" org.nutz.ioc.IocException: IocBean[druidDataSource] For object [druidDataSource] - type:[class com.alibaba.druid.pool.DruidDataSource]
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:249)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:270)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:160)
at cn.tba.pojo.Person.main(Person.java:62)
Caused by: org.nutz.ioc.ObjectLoadException: Object 'druidDataSource' without define!
at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:157)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:194)
... 3 more