NutzCN Logo
问答 怎么在service中注入dao?我目前是Null
发布于 2719天前 作者 qq_b2d7d3b8 1841 次浏览 复制 上一个帖子 下一个帖子
标签:

js文件:
var ioc = {
dataSource : {
//type : "org.apache.tomcat.jdbc.pool.DataSource",
type:"com.alibaba.druid.pool.DruidDataSource",
events : {
depose : 'close'
},
fields : {
driverClassName : 'xx',
url : 'xx',
initialSize:15,
maxIdle:15,
maxWait:80,
maxActive:100,
username : 'xx',
password : 'xx'
}
},
dao : {
type : "org.nutz.dao.impl.NutDao",
args : [{refer:'dataSource'}]
},
testService:{
type:"com.xx.service.TestService"
}
};
module java:
@InjectName("testModule")
@IocBean
public class TestModule {
@Inject
private TestService testService;
@At("tm/getCarBrandList")
@Ok("json")
public Result getCarBrandList() {
Result re = new Result();
testService.getEpSaleFollow2(re, 0L);
return re;
}
}
service java:
@IocBean
public class TestService {
private Logger logger=Logger.getLogger(TestService.class);
@Inject
private Dao dao;
public void getEpSaleFollow2(Result re){
List epSaleFollowList = dao.query(EpSaleFollow.class, Cnd.where("clId", "=", 1).desc("followDate").desc("id"));
re.setList1(epSaleFollowList);
}
}
debug的时候看了 dao是null
43行就是List epSaleFollowList = dao.query(EpSaleFollow.class, Cnd.where("clId", "=", 1).desc("followDate").desc("id"));
报错信息:
java.lang.NullPointerException
at com.qsh.service.TestService.getEpSaleFollow2(TestService.java:43)
at com.qsh.action.TestModule.getCarBrandList(TestModule.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:40)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:119)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:179)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:277)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2381)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2370)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

2 回复

删掉

 testService:{
 type:"com.xx.service.TestService"
 }

既然有@IocBean/@Inject注解了, 不要在js里面又定义一次.

谢谢大佬,删掉就搞定了。

添加回复
请先登陆
回到顶部