配置连接池
var ioc={
dataSource : {
type : "com.mchange.v2.c3p0.ComboPooledDataSource",
events : {
depose : 'close'
},
fields : {
driverClass : 'com.mysql.jdbc.Driver',
jdbcUrl : 'jdbc:mysql:///test',
user : 'root',
password : '11800'
}
},
dao:{
type:"org.nutz.dao.impl.NutDao",
args:[{ refer : "dataSource" }]
}
}
入口主函数
@IocBy(type = ComboIocProvider.class, args = {"*js","*anno", "com.modules","*tx"})
@Modules(scanPackage=true)
public class ComeNutz {
}
action
@IocBean
public class LoginerAction {
@Inject
private Dao dao;
@At("/login")
@Ok("redirect:login.jsp")
public void login(){
int i=dao.count(Loginer.class);
System.out.println("==============="+i);
}
web.xml配置
<filter>
<filter-name>entrance</filter-name>
<filter-class>org.nutz.mvc.NutFilter</filter-class>
<init-param>
<param-name>modules</param-name>
<param-value>com.modules.ComeNutz</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>entrance</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
启动不报错,请求/login,报错
WARN [http-8080-2] - Error@/login :
org.nutz.ioc.IocException: create ioc bean fail name=loginerAction ioc define:
{
"type" :"com.modules.action.LoginerAction",
"singleton" :true,
"events" :{
},
"args" :[],
"fields" :[{
"name" :"dao",
"value" :{
"type" :"refer",
"value" :"dao"
},
"optional" :false
}],
"scope" :"app"
}
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:132)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:194)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:212)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:106)
...
Caused by: org.nutz.ioc.IocException: For object [dao] - type:[]
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:201)
at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:31)
...
Caused by: org.nutz.ioc.ObjectLoadException: Object 'dao' without define!
at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:140)
at org.nutz.ioc.loader.cached.CachedIocLoaderImpl.load(CachedIocLoaderImpl.java:47)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:169)
... 27 more
哪里错了呢,求解释!