1、conf/redis.properties
内容:
redis.host=127.0.0.1
redis.port=6379
redis.timeout=2000
redis.password=123456
redis.database=0
import org.nutz.integration.jedis.RedisService;
import org.nutz.ioc.aop.Aop;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.IocBy;
import org.nutz.mvc.ioc.provider.ComboIocProvider;
import static org.nutz.integration.jedis.RedisInterceptor.jedis;
/**
* Created by Administrator on 2019/6/11.
*/
@IocBean(name="redis")
@IocBy(type =ComboIocProvider.class ,args={
"*js", "ioc/",
"*anno", "net.wendal.nutzbook",
"*jedis", // 添加这一行
""})
public class TestRedis {
public static void main(String[] args) {
TestRedis a = new TestRedis();
a.test1();
}
@Aop("redis") // 必须添加这个注解哦,否则jedis()会抛出空指针
public void test() {
jedis().set("name", "aaa");
}
@Inject
RedisService redisService;
public void test1() {
redisService.set("wendal", "https://nutz.cn");
}
}
java.lang.NullPointerException
at controllers.TestRedis.test(TestRedis.java:32)
at controllers.TestRedis.main(TestRedis.java:27)