NutzCN Logo
精华 nutz使用@Cache异常 大神看下是否是这么使用的
发布于 3142天前 作者 SniperZj 1706 次浏览 复制 上一个帖子 下一个帖子
标签:
@At("/user")
@Fail("http:500")
@IocBean
@Ok("json")
public class UserModule {
	@Inject
	protected Dao dao;

	@At
	@Cache(expire=600, key="'USER.getUserById'+#args[0]")
	public User getUserById(Long id){
		return dao.fetch(User.class,id);
	}
}
异常:
 For example:> "SELECT * FROM t_user  WHERE id=1"
2016-05-17 10:09:50,686 [http-apr-8080-exec-10] WARN  org.nutz.mvc.impl.processor.FailProcessor - Error@/user/getUserByid :
java.lang.NullPointerException
	at com.jarvis.cache.AbstractCacheManager.getCacheWrapper(AbstractCacheManager.java:441)
	at com.jarvis.cache.AbstractCacheManager.loadData(AbstractCacheManager.java:317)
	at com.jarvis.cache.AbstractCacheManager.proceed(AbstractCacheManager.java:234)
	at org.nutz.integration.autoloadcache.AutoLoadCacheAopInterceptor.filter(AutoLoadCacheAopInterceptor.java:39)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60)
	at com.zhangjie.project.module.UserModule$$NUTZAOP.getUserById(UserModule.java:1)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	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:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	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:196)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)

>>>>>>>>>>>>>>>>>>>>>>>>
配置
var ioc = {
		
		conf : {
			type : "org.nutz.ioc.impl.PropertiesProxy",
			fields : {
				paths : [ "custom/" ]
			}
		},
		jedisPoolConfig : {
	        type : "redis.clients.jedis.JedisPoolConfig",
	        fields : {
	            testWhileIdle : true,
	            maxTotal : 100
	        }
	    },
	    shardedJedisPool : {
	        type : "redis.clients.jedis.ShardedJedisPool",
	        args : [ {
	            refer : "jedisPoolConfig"
	        }, [ {
	            type : "redis.clients.jedis.JedisShardInfo",
	            args : [ {
	                java : "$conf.get('redis.host', 'localhost')"
	            }, 6379, "instance:01" ]
	        } ] ],
	        events : {
	            depose : "destroy"
	        }
	    },
	    autoLoadConfig : {
	        type : "com.jarvis.cache.to.AutoLoadConfig",
	        fields : {
	            threadCnt : 10,
	            maxElement : 20000,
	            printSlowLog : true,
	            slowLoadTime : 500,
	            sortType : 1,
	            checkFromCacheBeforeLoad : true,
	            autoLoadPeriod : 50
	        }
	    },
	    hessianSerializer : {
	        type : "com.jarvis.cache.serializer.HessianSerializer"
	    },
	    cachePointCut : {
	        type : "com.jarvis.cache.redis.ShardedCachePointCut",
	        args : [ {
	            refer : "autoLoadConfig"
	        } ],
	        fields : {
	            serializer : {
	                refer : "hessianSerializer"
	            },
	            shardedJedisPool : {
	                refer : "shardedJedisPool"
	            },
	            namespace : 'test_hessian'
	        },
	        events : {
	            depose : "destroy"
	        }
	    },
        dataSource : {
            type : "com.alibaba.druid.pool.DruidDataSource",
            events : {
                create : "init",
                depose : 'close'
            },
            fields : {
            	url : {
    				java : "$conf.get('url')"
    			},
    			username : {
    				java : "$conf.get('username')"
    			},
    			password : {
    				java : "$conf.get('password')"
    			},
                maxWait: 15000, 
                defaultAutoCommit : false, // 提高fastInsert的性能
                testWhileIdle : true,
                validationQuery : "select 1" ,//验证连接是否有效
                maxActive : 100 //连接池的最大数据库连接数。设为0表示无限制
            }
        },
        dao : {
            type : "org.nutz.dao.impl.NutDao",
            args : [{refer:"dataSource"}]
        }
};


9 回复

AutoLoadCache和Nutz均为最新版吗?

nutz 是最新的1.r.56.r3 我是把nutz 源码 和 AutoLoadCache4.4的源码放到项目里方便学习调试 不是直接用的jar 应该没多大关系吧难道路径找不到吗。。。

插件换成AutoLoadCache官方的试试

换了 com.jarvis.cache.admin.servlet.NutzCacheManagerConfig 还是 java.lang.NullPointerException

https://github.com/qiujiayu/AutoLoadCache/pull/12

我给它提交了个pull req, 就判断一下autoloadTO是否为null,既然你直接弄源码, 改一下试试吧

嗯好用了 不错 bean 好像要序列化 implement java.io.Serializable 不然要报错 ..must implement java.io.Serializable

默认使用HessianSerializer 的话,是可以不用 implement java.io.Serializable的,不过建议还是加上,方便其它地方使用。

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