不用--auth时可以连接并插数据,
使用安全连接时,如下加上用户名和密码会报错,请问除了改配置文件还需要改其他的吗:
@Test
public void insertTest() {
// 插入操作
User user = new User();
user.setAge("12");
user.setId("102");
user.setName("tom1");
userService.insert(user);
List<User> users = userService.query(ZMoDoc.NEW("id", "102"));
Assert.assertEquals(user, users.get(0));
}
zMongo : {
args : ["perfdba", "hope123", "127.0.0.1", 27017],
factory : "org.nutz.mongo.ZMongo#me"
},
org.nutz.ioc.IocException: [userService, zMongo] # FAIL to create Ioc Bean name=[zMongo]
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.ReferTypeValue.get(ReferTypeValue.java:26)
at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:31)
at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:135)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:146)
at com.hoperun.elvish.UserServiceTest.setUp(UserServiceTest.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.nutz.lang.born.BorningException: Fail to born 'org.nutz.mongo.ZMongo'
by args: [
@(perfdba)
@(hope123)
@(127.0.0.1)
@(27017)] becasue:
java.lang.IllegalArgumentException: source can not be null
at org.nutz.lang.born.MethodBorning.born(MethodBorning.java:20)
at org.nutz.ioc.weaver.DefaultWeaver.born(DefaultWeaver.java:67)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:114)
... 32 more
Caused by: java.lang.IllegalArgumentException: source can not be null
at com.mongodb.assertions.Assertions.notNull(Assertions.java:37)
at com.mongodb.MongoCredential.<init>(MongoCredential.java:233)
at com.mongodb.MongoCredential.createMongoCRCredential(MongoCredential.java:144)
at org.nutz.mongo.ZMongo.me(ZMongo.java:78)
at org.nutz.mongo.ZMongo.me(ZMongo.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.nutz.lang.born.MethodBorning.born(MethodBorning.java:17)
... 34 more