NutzCN Logo
问答 nutz集成mongodb 问题
发布于 2896天前 作者 menglinxi 2418 次浏览 复制 上一个帖子 下一个帖子
标签:

mongodb.json配置

var ioc={
zMongo : {
args : ["xxxxx", 27017], 
factory : "org.nutz.mongo.ZMongo#me"
},

zMoDB : {
args : ["adsmongodb"],
factory : "$zMongo#db"
},
zMoCoClick: {
args : ["click"],
factory : "$zMoDB#c"
}

}

service写法

@IocBean
public class ClickServcie extends Service{
    private static final Log log = Logs.get();
    @Inject
    protected ZMongo zMongo;  //注意大小写与配置的名字一致
    @Inject
    protected ZMoDB zMoDB; // 当前数据
    @Inject
    ZMoCo zMoCoClick;
    @Inject
    Dao dao;
}

配置文件里和类里的变量对应是什么样?

11 回复

一般来说, 没有人会review...

org.nutz.ioc.IocException: [clickServcie, zMoCoClick] # FAIL to create Ioc Bean name=[zMoCoClick]
org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:149)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:31)
org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:135)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:146)
org.apache.jsp.click_jsp._jspService(click_jsp.java:110)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.nutz.mvc.NutFilter.nextChain(NutFilter.java:226)
org.nutz.mvc.NutFilter.doFilter(NutFilter.java:201)
root cause

org.nutz.lang.InvokingException: Fail to invoke [org.nutz.mongo.ZMoDB].c() by args:
click
For the reason: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=120.132.17.135:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}]
org.nutz.lang.Invoking.invoke(Invoking.java:195)
org.nutz.lang.Mirror.invoke(Mirror.java:1100)
org.nutz.ioc.impl.ObjectMakerImpl$1.born(ObjectMakerImpl.java:89)
org.nutz.ioc.weaver.DefaultWeaver.born(DefaultWeaver.java:67)
org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:114)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:31)
org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:135)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:146)
org.apache.jsp.click_jsp._jspService(click_jsp.java:110)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.nutz.mvc.NutFilter.nextChain(NutFilter.java:226)
org.nutz.mvc.NutFilter.doFilter(NutFilter.java:201)
root cause

com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=120.132.17.135:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}]
com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:369)
com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:101)
com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.(ClusterBinding.java:75)
com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.(ClusterBinding.java:71)
com.mongodb.binding.ClusterBinding.getReadConnectionSource(ClusterBinding.java:63)
com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:210)
com.mongodb.operation.ListCollectionsOperation.execute(ListCollectionsOperation.java:172)
com.mongodb.operation.ListCollectionsOperation.execute(ListCollectionsOperation.java:80)
com.mongodb.Mongo.execute(Mongo.java:772)
com.mongodb.Mongo$2.execute(Mongo.java:759)
com.mongodb.OperationIterable.iterator(OperationIterable.java:47)
com.mongodb.OperationIterable.forEach(OperationIterable.java:70)
com.mongodb.MappingIterable.forEach(MappingIterable.java:50)
com.mongodb.MappingIterable.into(MappingIterable.java:60)
com.mongodb.DB.getCollectionNames(DB.java:253)
com.mongodb.DB.collectionExists(DB.java:476)
org.nutz.mongo.ZMoDB.c(ZMoDB.java:30)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.nutz.lang.Invoking$DefaultInvoker.invoke(Invoking.java:47)
org.nutz.lang.Invoking.invoke(Invoking.java:192)
org.nutz.lang.Mirror.invoke(Mirror.java:1100)
org.nutz.ioc.impl.ObjectMakerImpl$1.born(ObjectMakerImpl.java:89)
org.nutz.ioc.weaver.DefaultWeaver.born(DefaultWeaver.java:67)
org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:114)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:31)
org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:135)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:146)
org.apache.jsp.click_jsp._jspService(click_jsp.java:110)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.nutz.mvc.NutFilter.nextChain(NutFilter.java:226)
org.nutz.mvc.NutFilter.doFilter(NutFilter.java:201)

java.net.SocketTimeoutException: connect timed out

这是连不上, 防火墙没放行端口吧

org.nutz.ioc.IocException: [clickServcie, zMoCoClick] # FAIL to create Ioc Bean name=[zMoCoClick]
org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:149)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:31)
org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:135)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:146)
org.apache.jsp.click_jsp._jspService(click_jsp.java:110)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.nutz.mvc.NutFilter.nextChain(NutFilter.java:226)
org.nutz.mvc.NutFilter.doFilter(NutFilter.java:201)
root cause

org.nutz.lang.InvokingException: Fail to invoke [org.nutz.mongo.ZMoDB].c() by args:
click
For the reason: Colection noexitst: adsmongodb.click
org.nutz.lang.Invoking.invoke(Invoking.java:195)
org.nutz.lang.Mirror.invoke(Mirror.java:1100)
org.nutz.ioc.impl.ObjectMakerImpl$1.born(ObjectMakerImpl.java:89)
org.nutz.ioc.weaver.DefaultWeaver.born(DefaultWeaver.java:67)
org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:114)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:31)
org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:135)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:146)
org.apache.jsp.click_jsp._jspService(click_jsp.java:110)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.nutz.mvc.NutFilter.nextChain(NutFilter.java:226)
org.nutz.mvc.NutFilter.doFilter(NutFilter.java:201)
root cause

java.lang.RuntimeException: Colection noexitst: adsmongodb.click
org.nutz.lang.Lang.makeThrow(Lang.java:132)
org.nutz.mongo.ZMoDB.c(ZMoDB.java:31)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.nutz.lang.Invoking$DefaultInvoker.invoke(Invoking.java:47)
org.nutz.lang.Invoking.invoke(Invoking.java:192)
org.nutz.lang.Mirror.invoke(Mirror.java:1100)
org.nutz.ioc.impl.ObjectMakerImpl$1.born(ObjectMakerImpl.java:89)
org.nutz.ioc.weaver.DefaultWeaver.born(DefaultWeaver.java:67)
org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:114)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:31)
org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:135)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:146)
org.apache.jsp.click_jsp._jspService(click_jsp.java:110)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.nutz.mvc.NutFilter.nextChain(NutFilter.java:226)
org.nutz.mvc.NutFilter.doFilter(NutFilter.java:201)

集合不存在

如果需要自动建

factory : "$zMoDB#c"
// 改成
factory : "$zMoDB#cc"

db要创建吗?如果是自动创建,下次系统重启会不会把原来的冲掉?

org.nutz.ioc.IocException: [clickServcie, zMoCoClick] # FAIL to create Ioc Bean name=[zMoCoClick]
org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:149)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:31)
org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:135)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:146)
org.apache.jsp.click_jsp._jspService(click_jsp.java:110)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.nutz.mvc.NutFilter.nextChain(NutFilter.java:226)
org.nutz.mvc.NutFilter.doFilter(NutFilter.java:201)
root cause

org.nutz.lang.InvokingException: Don't know how to invoke [org.nutz.mongo.ZMoDB].cc() by args:
click
org.nutz.lang.Invoking.(Invoking.java:159)
org.nutz.lang.Mirror.getInvoking(Mirror.java:1023)
org.nutz.lang.Mirror.invoke(Mirror.java:1100)
org.nutz.ioc.impl.ObjectMakerImpl$1.born(ObjectMakerImpl.java:89)
org.nutz.ioc.weaver.DefaultWeaver.born(DefaultWeaver.java:67)
org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:114)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:31)
org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:135)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
org.nutz.ioc.impl.NutIoc.get(NutIoc.java:146)
org.apache.jsp.click_jsp._jspService(click_jsp.java:110)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.nutz.mvc.NutFilter.nextChain(NutFilter.java:226)
org.nutz.mvc.NutFilter.doFilter(NutFilter.java:201)

zMoCoClick: {
args : ["click"],
factory : "$zMoDB#cc"
}

我晚上试试,创建一个集合先。

说错了.... cc有2个参数, 所以应该是这样

zMoCoClick: {
args : ["click", false],
factory : "$zMoDB#cc"
}

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