@Configuration
public class MyRedisConfig {
@Bean(name="genericJackson2JsonRedisSerializer")
public GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer() {
return new GenericJackson2JsonRedisSerializer();
}
@Bean(name = "myRedisTemplate")
public RedisTemplate
测试:
public class SpringbootCacheApplicationTests {
@Autowired
private EmployeeMapper employeeMapper;
@Qualifier("myRedisTemplate")
@Autowired
RedisTemplate myRedisTemplate;
@Test
public void test02() {
Employee employee = employeeMapper.getEmpById(1);
myRedisTemplate.opsForValue().set("emp-1", employee);
}
}
如果使用Jackson2JsonRedisSerializer在反序列化时会遇到问题,因为没有具体泛型或泛型为Object时,
会将缓存中的数据反序列化为LinkedHashMap,而假如我们需要的是Employee对象,因此就会抛出一个异常。
java.lang.ClassCastException: java.base/java.util.LinkedHashMap cannot be cast to com.springboot.domain.Employeegithub:https://github.com/liuzhoujian/springboot-cache
首先看看 WeakReference
wiki 上 Weak reference 的一个例子:
public class ReferenceTest {
public static void main(String[] args) throws InterruptedException {
WeakReference r = new Wea
有一个线上环境使用的是c3p0数据库,为外部提供接口服务。最近访问压力增大后台tomcat的日志里面频繁出现
com.mchange.v2.resourcepool.TimeoutException: A client timed out while waiting to acquire a resource from com.mchange.v2.resourcepool.BasicResou
https://weblogs.java.net/blog/mriem/archive/2013/11/22/jsf-tip-45-create-composite-component-custom-namespace
When you developed a composite component the namespace you would be seeing would
一、复本集为什么要加入Arbiter这个角色 回答这个问题,要从复本集的存活条件和Aribter服务器的特性两方面来说。 什么是Artiber? An arbiter does
not have a copy of data set and
cannot become a primary. Replica sets may have arbiters to add a
# include <stdio.h>
int main(void)
{
int a[5] = {1, 2, 3, 4, 5};
//a 是数组的名字 5是表示数组元素的个数,并且这五个元素分别用a[0], a[1]...a[4]
int i;
for (i=0; i<5; ++i)
printf("%d\n",