NutzCN Logo
问答 nutz和redis整合
发布于 2803天前 作者 qq_64f81159 3785 次浏览 复制 上一个帖子 下一个帖子
标签:

简单的写了一个redis和nutz整合的例子,将登陆的用户名密码保存到redis里面去,其中config目录有datasource.json,配置信息为:
var ioc = {
conf : {
type : "org.nutz.ioc.impl.PropertiesProxy",
fields : {
paths : ["config/"]
}
},
dataSource:{
type:"com.alibaba.druid.pool.DruidDataSource",
events:{
depose:"close"
},
fields:{
url:"jdbc:mysql://127.0.0.1:3306/redis?useUnicode=true&characterEncoding=utf8",
username:"root",
password:"nothing",
maxActive:20,
testWhileIdle:true,
validationQuery:"SELECT COUNT('x')",
removeAbandoned:true ,
removeAbandonedTimeout:1800,
filters:"stat"
}
},
dao : {
type : "org.nutz.dao.impl.NutDao",
args : [{refer:'dataSource'}]
}

}
redis.properties配置信息为

redis.host=localhost
redis.port=6379
redis.timeout=2000
#redis.password=wendal.net
redis.database=0
#redis.mode=cluster

两配置文件在都在config目录下,两文件是平级的
存入的代码为

@IocBean
public class UserService {
	@Inject 
	JedisAgent jedisAgent;
	
	public void setUser(){
		  Jedis jedis = null;
		    try { // JDK6的写法, 长长的try-finally
		        jedis = jedisAgent.getResource();
		        User user = new User();
		        user.setUsername("张三");
		        user.setPassword("123");
		        String key="t:body:"+R.UU32();
				jedis.set(key,Json.toJson(user));
				String value = jedis.get(key);
				System.err.println(value);
			}
			finally {
				Streams.safeClose(jedis);
			}
	}
}

现在报错了错误信息为

org.nutz.ioc.IocException: [jedisPool, jedisPoolConfig] # FAIL to create Ioc Bean name=[jedisPoolConfig]
	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.ReferValue.get(ReferValue.java:24)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:75)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
	at org.nutz.integration.jedis.JedisAgent.getJedisPool(JedisAgent.java:60)
	at org.nutz.integration.jedis.JedisAgent.jedis(JedisAgent.java:49)
	at org.nutz.integration.jedis.JedisAgent.getResource(JedisAgent.java:54)
	at com.kanq.service.UserService.setUser(UserService.java:22)
	at com.kanq.modules.UserModule.login(UserModule.java:40)
	at com.kanq.modules.UserModule$$FASTCLASS._invoke(UserModule.java:1)
	at org.nutz.lang.reflect.AbstractFastClass.invoke(AbstractFastClass.java:143)
	at org.nutz.lang.reflect.FastClassFactory.invoke(FastClassFactory.java:67)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:27)
	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:198)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoClassDefFoundError: net/sourceforge/cobertura/coveragedata/TouchCollector
	at org.apache.commons.pool2.impl.BaseObjectPoolConfig.__cobertura_init(BaseObjectPoolConfig.java)
	at org.apache.commons.pool2.impl.BaseObjectPoolConfig.<clinit>(BaseObjectPoolConfig.java)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at org.nutz.lang.born.EmptyArgsConstructorBorning.born(EmptyArgsConstructorBorning.java:16)
	at org.nutz.ioc.weaver.DefaultWeaver.born(DefaultWeaver.java:67)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:114)
	... 40 more
Caused by: java.lang.ClassNotFoundException: net.sourceforge.cobertura.coveragedata.TouchCollector
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
	... 49 more

请帮忙 谢谢了。

5 回复
at org.apache.commons.pool2.impl.BaseObjectPoolConfig.__cobertura_init(BaseObjectPoolConfig.java)

肯定是用过代码覆盖工具处理过 https://github.com/cobertura/cobertura

如果没有,那么pool2.jar 不是原版, 换官方原版

最终确定是 apache commons pool2 2.4.0 版特有的bug, 使用2.4.1/2.4.2 均正常

我运气是不是太好了

我觉得刚新版本好点,从2.4.1、2.4.2,、2.4版本考虑太新了不好,大版本应该是稳定的 就选了2.4

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