NutzCN Logo
问答 直接继承RedisService不能正常调用RedisService中的方法
发布于 2351天前 作者 weirhp 2305 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

nutz的版本1.r.62
```java
@IocBean
public class RemoteCacheService extends RedisService {
}

测试代码
public class RemoteCacheServiceTest {
private Ioc ioc;
@Before
public void before() throws ClassNotFoundException {
JsonLoader jsonLoader = new JsonLoader("/config");
AnnotationIocLoader annoLoader = new AnnotationIocLoader("/com/weirhp");
IocLoader iocLoader = new ComboIocLoader("*jedis");
IocLoader iocLoader2 = new ComboIocLoader(jsonLoader, annoLoader, iocLoader);
ioc = new NutIoc(iocLoader2);
}

    // 有问题
@Test
public void testSet() throws InterruptedException {
       RemoteCacheService cacheService = ioc.get(RemoteCacheService.class);
       cacheService.set("test", "111");
}

   // 没问题
   @Test
public void testSet2() throws InterruptedException {
    RedisService cacheService = ioc.get(RedisService.class);
    cacheService.set("test", "111");
}

}

```
java.lang.NullPointerException
at org.nutz.integration.jedis.RedisService.set(RedisService.java:40)
at net.cloudenjoy.test.index.RemoteCacheServiceTest.testLoadQuestion(RemoteCacheServiceTest.java:37)
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.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.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
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:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)

9 回复
@IocBean(fields="jedisAgent")

要在启动的@IocBy中申明引入"*jedis"

还是不行,异常信息如下:

org.nutz.ioc.IocException: IocBean[remoteCacheService] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:149)
	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 net.cloudenjoy.test.index.RemoteCacheServiceTest.testSet(RemoteCacheServiceTest.java:36)
	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.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.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	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:538)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Caused by: java.lang.RuntimeException: Fail to eval Injector for field: 'jedisAgent'
	at org.nutz.lang.Lang.wrapThrow(Lang.java:167)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:128)
	... 28 more
Caused by: java.lang.RuntimeException: java.lang.NoSuchFieldException: Can NOT find field [jedisAgent] in class [net.cloudenjoy.star.common.RemoteCacheService] and it's parents classes
	at org.nutz.lang.Lang.wrapThrow(Lang.java:184)
	at org.nutz.lang.Mirror.getInjecting(Mirror.java:1048)
	at org.nutz.ioc.weaver.FieldInjector.create(FieldInjector.java:17)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:125)
	... 28 more
Caused by: java.lang.NoSuchFieldException: Can NOT find field [jedisAgent] in class [net.cloudenjoy.star.common.RemoteCacheService] and it's parents classes
	at org.nutz.lang.Mirror.getField(Mirror.java:476)
	at org.nutz.lang.Mirror.getInjecting(Mirror.java:1039)
	... 30 more


RedisService什么版本的?

最新版里面是有jedisAgent属性的

也是1.r.62
M2_REPO/org/nutz/nutz-integration-jedis/1.r.62/nutz-integration-jedis-1.r.62.jar

好的,那我更新到最新版的

完美呀。。1.r.66 正常了,谢了

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