NutzCN Logo
问答 @Inject RedisService redisService;20190310
发布于 2114天前 作者 qq_6d75074b 1346 次浏览 复制 上一个帖子 下一个帖子
标签:
2019-03-10 11:57:22,819 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) DEBUG - Found mapping for [POST] path=/loginadmin : Login.loginadmin(Login.java:186)
2019-03-10 11:57:22,826 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'login'<class cn.Login>
2019-03-10 11:57:22,826 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) DEBUG - 	 >> Load definition name=login
2019-03-10 11:57:22,826 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:161) DEBUG - Found IocObject(login) in AnnotationIocLoader(packages=[cn, net.wendal.nutzbook])
2019-03-10 11:57:22,826 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209) DEBUG - 	 >> Make...'login'<class cn.Login>
2019-03-10 11:57:22,827 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:70) DEBUG - Load class cn.Login without AOP
2019-03-10 11:57:22,827 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:64) DEBUG - Save object 'login' to [app] 
2019-03-10 11:57:22,843 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'redisService'<class org.nutz.integration.jedis.RedisService>
2019-03-10 11:57:22,843 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) DEBUG - 	 >> Load definition name=redisService
2019-03-10 11:57:22,843 org.nutz.ioc.loader.map.MapLoader.load(MapLoader.java:67) DEBUG - Loading define for name=redisService
2019-03-10 11:57:22,843 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:161) DEBUG - Found IocObject(redisService) in JedisIocLoader@506656640
2019-03-10 11:57:22,843 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209) DEBUG - 	 >> Make...'redisService'<class org.nutz.integration.jedis.RedisService>
2019-03-10 11:57:22,843 org.nutz.ioc.impl.ScopeContext.remove(ScopeContext.java:84) DEBUG - Remove object 'login' from [app] 
2019-03-10 11:57:22,843 cn.core.mvc.LogTimeProcessor.process(LogTimeProcessor.java:28) DEBUG - [POST]URI=/xcbm/loginadmin 24ms
2019-03-10 11:57:22,843 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) WARN  - Error@/loginadmin :
org.nutz.ioc.IocException: IocBean[login] 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.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:116)
	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.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.core.mvc.LogTimeProcessor.process(LogTimeProcessor.java:23)
	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:202)
	at cn.core.mvc.MyNutFilter.doFilter(MyNutFilter.java:37)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at cn.core.util.XFilter.doFilter(XFilter.java:25)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: IocBean[login] fail at field=[redisService]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:135)
	... 39 more
Caused by: org.nutz.ioc.IocException: IocBean[redisService] For object [redisService] - type:[class org.nutz.integration.jedis.RedisService]
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:218)
	at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 41 more
Caused by: java.lang.NoClassDefFoundError: redis/clients/jedis/GeoUnit
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
	at java.lang.Class.getDeclaredMethods(Unknown Source)
	at org.nutz.ioc.aop.SimpleAopMaker.getInterceptorPairList(SimpleAopMaker.java:112)
	at org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:64)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:36)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
	... 43 more
Caused by: java.lang.ClassNotFoundException: redis.clients.jedis.GeoUnit
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1343)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1173)
	... 50 more

package cn;

import javax.servlet.http.HttpSession;

import org.nutz.dao.Chain;
import org.nutz.dao.Cnd;
import org.nutz.integration.jedis.RedisService;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Filters;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import cn.admin.bean.SysStatus;
import cn.admin.bean.SysUserinfo;
import cn.core.util.BaseModule;
import cn.core.util.ResultBean;
import cn.core.util.XFilter;
import cn.student.bean.Generalrules;
import cn.student.bean.Student;

@IocBean
public class Login extends BaseModule {
	@Inject
	RedisService redisService;

	@At("/loginadmin")
	@Ok("json")
	@Filters
	public Object loginadmin(@Param("userno") String userno, @Param("userpwd") String userpwd) {
		ResultBean result = new ResultBean();
		SysUserinfo user = null;
		try {
			user = dao.fetch(SysUserinfo.class, Cnd.where("userno", "=", userno));
			if (user == null) {
				result.setStatusCode(-1);
				result.setStatusMessage("用户编码不正确!");
				return result;
			}
			user = dao.fetch(SysUserinfo.class, Cnd.where("userno", "=", userno).and("userpwd", "=", userpwd));
			if (user == null) {
				result.setStatusCode(-1);
				result.setStatusMessage("用户密码错误!");
				return result;
			} else {
				String sessionid = redisService.get(userno);
				HttpSession session = XFilter.requests.get().getSession();

				// 强制断掉之前登陆的session
				if (null != sessionid) {
					HttpSession sess = session.getSessionContext().getSession(sessionid);
					sess.invalidate();
				}
				redisService.set(userno, session.getId());

				session.setAttribute("usertype", "admin");
				session.setAttribute("user", user);
				result.setStatusCode(1);
				result.setStatusMessage("登录成功,返回登陆界面!");
				super.addSystemLogs("管理员登录", user.getUserno() + user.getUsername() + super.getIpAddr() + "管理员登录成功!");
				return result;
			}
		} catch (Exception e) {
			result.setStatusCode(-1);
			result.setStatusMessage("登录异常,请稍后再试!");
			return result;
		}
	}
}

13 回复

jedis版本低

package cn;

import org.nutz.mvc.adaptor.JsonAdaptor;
import org.nutz.mvc.annotation.AdaptBy;
import org.nutz.mvc.annotation.By;
import org.nutz.mvc.annotation.ChainBy;
import org.nutz.mvc.annotation.Fail;
import org.nutz.mvc.annotation.Filters;
import org.nutz.mvc.annotation.IocBy;
import org.nutz.mvc.annotation.Modules;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.SetupBy;
import org.nutz.mvc.filter.CheckSession;
import org.nutz.mvc.ioc.provider.ComboIocProvider;

//@Localization(value="msg/", defaultLocalizationKey="zh-CN")//国际化,暂时用不了
@Filters(@By(type = CheckSession.class, args = { "user", "/toLogin" }))
@Ok("json:full")
@Fail("jsp:jsp.500")
@SetupBy(value = MainSetup.class)
//请注意星号!!不要拷贝少了
@IocBy(type = ComboIocProvider.class, args = { "*js", "ioc/", "*anno", "cn", "net.wendal.nutzbook", "*jedis", "*tx", // 事务拦截
"*async"// 异步执行aop
})
@Modules(scanPackage = true)
@ChainBy(args = "mvc/nutz-mvc-chain.js")
@AdaptBy(type = JsonAdaptor.class)
public class MainModule {

}

Windows 版本只搜索到3.2版本的,你哪里有没有Windows高版本的jedis。。。,jedis-2.4.2.jar

支持jedis的最低版本是???

jedis最新是2.10.0以上了

jedis是不区分操作系统的

谢谢!!!!

进入
String sessionid = redisService.get(userno);
报错
2019-03-10 12:20:16,801 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'jedisPool'<class redis.clients.util.Pool>
2019-03-10 12:20:16,816 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) DEBUG - >> Load definition name=jedisPool
2019-03-10 12:20:16,817 org.nutz.ioc.loader.map.MapLoader.load(MapLoader.java:67) DEBUG - Loading define for name=jedisPool
2019-03-10 12:20:16,832 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:161) DEBUG - Found IocObject(jedisPool) in JedisIocLoader@870584203
2019-03-10 12:20:16,848 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209) DEBUG - >> Make...'jedisPool'<class redis.clients.util.Pool>

String sessionid = redisService.get(userno);


2019-03-10 12:20:16,801 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'jedisPool'<class redis.clients.util.Pool>
2019-03-10 12:20:16,816 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) DEBUG - 	 >> Load definition name=jedisPool
2019-03-10 12:20:16,817 org.nutz.ioc.loader.map.MapLoader.load(MapLoader.java:67) DEBUG - Loading define for name=jedisPool
2019-03-10 12:20:16,832 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:161) DEBUG - Found IocObject(jedisPool) in JedisIocLoader@870584203
2019-03-10 12:20:16,848 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209) DEBUG - 	 >> Make...'jedisPool'<class redis.clients.util.Pool>

redis.properties


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

ioc 已经配置了Mysql,redis怎么配置???急,在线等,谢谢!!!!

var ioc = {
        conf : {
            type : "org.nutz.ioc.impl.PropertiesProxy",
            fields : {
                paths : ["custom/db.properties"]
            }
        },
        dataSource : {
            type : "com.alibaba.druid.pool.DruidDataSource",
            events : {
                create : "init",
                depose : 'close'
            },
            fields : {
                url : {java:"$conf.get('db.url')"},
                username : {java:"$conf.get('db.username')"},
                password : {java:"$conf.get('db.password')"},
                testWhileIdle : true,
                validationQuery : {java:"$conf.get('db.validationQuery')"},
                maxActive : {java:"$conf.get('db.maxActive')"},
                filters : "mergeStat",
                connectionProperties : "druid.stat.slowSqlMillis=2000"
            }
        },
        dao : {
            type : "org.nutz.dao.impl.NutDao",
            args : [{refer:"dataSource"}]
        }
};
2019-03-10 13:05:11,361 cn.core.mvc.LogTimeProcessor.process(LogTimeProcessor.java:28) DEBUG - [POST]URI=/xcbm/loginadmin 58ms
2019-03-10 13:05:11,361 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) WARN  - Error@/loginadmin :
org.nutz.ioc.IocException: IocBean[login] 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.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:116)
	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.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.core.mvc.LogTimeProcessor.process(LogTimeProcessor.java:23)
	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:202)
	at cn.core.mvc.MyNutFilter.doFilter(MyNutFilter.java:37)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at cn.core.util.XFilter.doFilter(XFilter.java:25)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: IocBean[login] fail at field=[redisService]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:135)
	... 39 more
Caused by: org.nutz.ioc.IocException: IocBean[redisService -> redis] 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.aop.config.impl.AnnotationAopConfigration.makeIt(AnnotationAopConfigration.java:23)
	at org.nutz.ioc.aop.config.impl.AnnotationAopConfigration.makeIt(AnnotationAopConfigration.java:18)
	at org.nutz.ioc.aop.SimpleAopMaker.getInterceptorPairList(SimpleAopMaker.java:117)
	at org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:64)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:36)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
	at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 41 more
Caused by: java.lang.RuntimeException: Fail to eval Injector for field: 'jedisPool'
	at org.nutz.lang.Lang.wrapThrow(Lang.java:167)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:128)
	... 51 more
Caused by: java.lang.RuntimeException: java.lang.NoSuchFieldException: Can NOT find field [jedisPool] in class [org.nutz.integration.jedis.RedisInterceptor] 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)
	... 51 more
Caused by: java.lang.NoSuchFieldException: Can NOT find field [jedisPool] in class [org.nutz.integration.jedis.RedisInterceptor] and it's parents classes
	at org.nutz.lang.Mirror.getField(Mirror.java:476)
	at org.nutz.lang.Mirror.getInjecting(Mirror.java:1039)
	... 53 more

var ioc = {
    conf : {
        type : "org.nutz.ioc.impl.PropertiesProxy",
        fields : {
            paths : ["custom/redis.properties"]
        }
    },
    jedisPoolConfig : {
        type : "redis.clients.jedis.JedisPoolConfig",
        fields : {
            testWhileIdle : true, // 空闲时测试,免得redis连接空闲时间长了断线
            maxTotal : {java : "$conf.getInt('redis.maxTotal', 100)"} // 一般都够了吧
        }
    },
    jedisPool : {
        type : "redis.clients.jedis.JedisPool",
        args : [
            {refer : "jedisPoolConfig"},
            {java : "$conf.get('redis.host', 'localhost')"},
            {java : "$conf.getInt('redis.port', 6379)"},
            {java : "$conf.getInt('redis.timeout', 2000)"},
            {java : "$conf.get('redis.password')"},
            {java : "$conf.getInt('redis.database', 0)"}
        ],
        fields : {},
        events : {
            depose : "destroy" // 关闭应用时必须关掉呢
        }
    },
    redis : {
        type : "org.nutz.integration.jedis.RedisInterceptor",
        fields : {
            jedisPool : {refer:"jedisPool"}
        }
    },
    redisService : {
        type : "org.nutz.integration.jedis.RedisService"
    },
    pubSubService : {
        type : "org.nutz.integration.jedis.pubsub.PubSubService",
        fields : {
            jedisPool : {refer:"jedisPool"}
        },
        events : {
            depose : "depose"
        }
    }
};
添加回复
请先登陆
回到顶部