- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在开发 Spring Boot + Spring Data Redis 示例。在此示例中,尝试使用 @EnableRedisHttpSession
并从 https://www.youtube.com/watch?v=_M8xoagybzU&t=231s 获取了代码引用.
我开发了代码并尝试运行该示例。我收到以下错误。我不知道发生了什么事?另外,我不清楚为什么错误 Caused by: java.lang.ClassNotFoundException: com.example.Order
。
Caused by: org.springframework.data.redis.serializer.SerializationException: Cannot deserialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to deserialize payload. Is the byte array a result of corresponding serialization for DefaultDeserializer?; nested exception is org.springframework.core.NestedIOException: Failed to deserialize object type; nested exception is java.lang.ClassNotFoundException: com.example.Order
at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.deserialize(JdkSerializationRedisSerializer.java:84) ~[spring-data-redis-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.data.redis.serializer.DefaultRedisElementReader.read(DefaultRedisElementReader.java:48) ~[spring-data-redis-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.data.redis.serializer.RedisSerializationContext$SerializationPair.read(RedisSerializationContext.java:226) ~[spring-data-redis-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.data.redis.cache.RedisCache.deserializeCacheValue(RedisCache.java:254) ~[spring-data-redis-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.data.redis.cache.RedisCache.lookup(RedisCache.java:88) ~[spring-data-redis-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.cache.support.AbstractValueAdaptingCache.get(AbstractValueAdaptingCache.java:58) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.cache.interceptor.AbstractCacheInvoker.doGet(AbstractCacheInvoker.java:73) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.cache.interceptor.CacheAspectSupport.findInCaches(CacheAspectSupport.java:554) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.cache.interceptor.CacheAspectSupport.findCachedItem(CacheAspectSupport.java:519) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:401) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:345) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at com.example.service.OrderService$$EnhancerBySpringCGLIB$$2fc6ad4.byId(<generated>) ~[classes/:na]
at com.example.RedisApplication.lambda$4(RedisApplication.java:97) [classes/:na]
at com.example.RedisApplication.measure(RedisApplication.java:89) [classes/:na]
at com.example.RedisApplication.lambda$3(RedisApplication.java:98) [classes/:na]
at com.example.RedisApplication.lambda$0(RedisApplication.java:57) [classes/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:804) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
... 5 common frames omitted
Caused by: org.springframework.core.serializer.support.SerializationFailedException: Failed to deserialize payload. Is the byte array a result of corresponding serialization for DefaultDeserializer?; nested exception is org.springframework.core.NestedIOException: Failed to deserialize object type; nested exception is java.lang.ClassNotFoundException: com.example.Order
at org.springframework.core.serializer.support.DeserializingConverter.convert(DeserializingConverter.java:78) ~[spring-core-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.core.serializer.support.DeserializingConverter.convert(DeserializingConverter.java:36) ~[spring-core-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.deserialize(JdkSerializationRedisSerializer.java:82) ~[spring-data-redis-2.1.2.RELEASE.jar:2.1.2.RELEASE]
... 24 common frames omitted
Caused by: org.springframework.core.NestedIOException: Failed to deserialize object type; nested exception is java.lang.ClassNotFoundException: com.example.Order
at org.springframework.core.serializer.DefaultDeserializer.deserialize(DefaultDeserializer.java:75) ~[spring-core-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.core.serializer.support.DeserializingConverter.convert(DeserializingConverter.java:73) ~[spring-core-5.1.2.RELEASE.jar:5.1.2.RELEASE]
... 26 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.example.Order
at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.8.0_151]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_151]
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) ~[na:1.8.0_151]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.8.0_151]
at java.lang.Class.forName0(Native Method) ~[na:1.8.0_151]
at java.lang.Class.forName(Unknown Source) ~[na:1.8.0_151]
at java.io.ObjectInputStream.resolveClass(Unknown Source) ~[na:1.8.0_151]
at org.springframework.core.ConfigurableObjectInputStream.resolveClass(ConfigurableObjectInputStream.java:80) ~[spring-core-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source) ~[na:1.8.0_151]
at java.io.ObjectInputStream.readClassDesc(Unknown Source) ~[na:1.8.0_151]
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source) ~[na:1.8.0_151]
at java.io.ObjectInputStream.readObject0(Unknown Source) ~[na:1.8.0_151]
at java.io.ObjectInputStream.readObject(Unknown Source) ~[na:1.8.0_151]
at org.springframework.core.serializer.DefaultDeserializer.deserialize(DefaultDeserializer.java:72) ~[spring-core-5.1.2.RELEASE.jar:5.1.2.RELEASE]
... 27 common frames omitted
购物车.java
public class ShoppingCart implements Serializable{
private static final long serialVersionUID = 1L;
private final Collection<Order> orders = new ArrayList<>();
public void addOrder(Order order) {
this.orders.add(order);
}
public Collection<Order> getOrders(){
return this.orders;
}
}
CartSessionController.java
@Log
@Controller
@SessionAttributes("cart")
public class CartSessionController {
private final AtomicLong ids = new AtomicLong();
@ModelAttribute("cart")
ShoppingCart cart() {
log.info("Creating new cart");
return new ShoppingCart();
}
@GetMapping("/orders")
String Order(@ModelAttribute("cart") ShoppingCart cart, Model model) {
cart.addOrder(new Order(ids.incrementAndGet(), new Date(), Collections.emptyList()));
model.addAttribute("orders", cart.getOrders());
return "orders";
}
}
订单.java
@Data
@AllArgsConstructor
@NoArgsConstructor
@RedisHash("orders")
public class Order implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private Long Id;
@Indexed
private Date when;
@Reference
private List<LineItem> lineItems;
}
LineItem.java
@Data
@AllArgsConstructor
@NoArgsConstructor
@RedisHash("lineItems")
public class LineItem implements Serializable {
private static final long serialVersionUID = 1L;
@Indexed
private Long orderId;
@Id
private Long id;
private String description;
}
RedisApplication.java
@Log
@SpringBootApplication
@EnableRedisHttpSession
@EnableCaching
public class RedisApplication {
private final String TOPIC = "Chat";
@Autowired
private OrderRepository orderRepository;
@Autowired
private LineItemRepository lineItemRepository;
@Autowired
private OrderService OrderService;
private ApplicationRunner titleRunner(String title, ApplicationRunner rr) {
return args -> {
log.info(title.toUpperCase() + ":");
rr.run(args);
};
}
@Bean
ApplicationRunner geography(RedisTemplate<String, String> rt) {
return titleRunner("geography", args -> {
GeoOperations<String, String> geo = rt.opsForGeo();
geo.add("Sicily", new Point(13.361389, 38.155556), "Arigento");
geo.add("Ramesh", new Point(15.087269, 37.502669), "Catania");
geo.add("Anup", new Point(13.583333, 37.316667), "Palermo");
Circle circle = new Circle(new Point(13.583333, 37.316667),
new Distance(100, RedisGeoCommands.DistanceUnit.KILOMETERS));
GeoResults<GeoLocation<String>> radius = geo.radius("Sicily", circle);
radius.getContent().forEach(c -> log.info(c.toString()));
});
}
public static void main(String[] args) {
SpringApplication.run(RedisApplication.class, args);
}
//#####################
@Bean
CacheManager redisCache(RedisConnectionFactory connectionFactory) {
return RedisCacheManager.builder(connectionFactory).build();
}
private long measure(Runnable r) {
long start = System.currentTimeMillis();
r.run();
long stop = System.currentTimeMillis();
return start - stop;
}
@Bean
ApplicationRunner cache() {
return titleRunner("caching", a ->{
Runnable measure = () -> OrderService.byId(1L);
log.info("first "+measure(measure));
log.info("two "+measure(measure));
log.info("three "+measure(measure));
});
}
//#####################
@Bean
ApplicationRunner repositories() {
return titleRunner("repositories", args -> {
Long orderId = generateId();
List<LineItem> itemsList = Arrays.asList(
new LineItem(orderId, generateId(), "plunger"),
new LineItem(orderId, generateId(), "soup"),
new LineItem(orderId, generateId(), "cofee mug"));
itemsList.stream().map(lineItemRepository::save).forEach(li -> log.info(li.toString()));
Order order = new Order(orderId, new Date(), itemsList);
orderRepository.save(order);
Collection<Order> found = orderRepository.findByWhen(order.getWhen());
found.forEach(o -> log.info("found : " + o.toString()));
});
}
private Long generateId() {
long tmp = new Random().nextLong();
return Math.max(tmp, tmp * -1);
}
@Bean
ApplicationRunner pubSub(RedisTemplate<String, String> rt) {
return titleRunner("publish/subscribe", args ->{
rt.convertAndSend(TOPIC, "Hello World @ "+Instant.now().toString());
});
}
@Bean
RedisMessageListenerContainer listener(RedisConnectionFactory rcf) {
MessageListener ml = (message, pattern) -> {
String str = new String(message.getBody());
log.info("message from ' " + TOPIC + "':'" + str);
};
RedisMessageListenerContainer mlc = new RedisMessageListenerContainer();
mlc.setConnectionFactory(rcf);
mlc.addMessageListener(ml, new PatternTopic(TOPIC));
return mlc;
}
}
最佳答案
我按照 @Arnaud
的建议使用 >FLUSHALL
刷新 Redis 数据库,然后它工作正常。即使是现在,我也可以看到 SessionAttributes
和 SessionExpire
等的详细信息都保存在缓存中。
127.0.0.1:6379> KEYS *
1) "lineItems:3544713235909729939:idx"
2) "order-by-id::1"
3) "lineItems:orderId:4510658827505526003"
4) "Sicily"
5) "spring:session:expirations:1541668980000"
6) "lineItems:6802678421112514562"
7) "lineItems:4083773252419547322:idx"
8) "lineItems:4083773252419547322"
9) "lineItems:6802678421112514562:idx"
10) "spring:session:sessions:expires:ea0c3a35-b821-461b-8568-1cf972ba99cb"
11) "Anup"
12) "lineItems:3544713235909729939"
13) "orders:4510658827505526003:idx"
14) "orders:4510658827505526003"
15) "orders:when:1541667065759"
16) "Ramesh"
17) "lineItems"
18) "spring:session:sessions:ea0c3a35-b821-461b-8568-1cf972ba99cb"
19) "orders"
127.0.0.1:6379>
关于java - 由: org. springframework.data.redis.serializer.SerializationException引起 : Cannot deserialize; nested exception is org. springframework.core.seriali,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53204055/
刚开始处理Maven和Spring。当我尝试创建DAO和ResultSet然后运行应用程序时,抛出errors: Error:(4, 31) java: package org.springframe
问题: Error:(15, 10) java: cannot find symbol symbol: class SpringRunner Error:(16, 2) java: cannot
我正在尝试构建这个 RESTful 服务示例:https://spring.io/guides/gs/rest-service/GreetingController.java 的导入没有错误: pac
如果我尝试向构造函数注入(inject) Facebook 参数,我将尝试使用 facebook api 使用 spring + thymeleaf + hibernate 创建 Facebook 应
如何解决Spring中Bean的自动连接歧义?我们有一个 Dessert 接口(interface),并且有实现该接口(interface)(Dessert)的三种不同的甜点(Bean)。 今天的甜点
请问为什么我的 pom.xml 文件中会出现此错误 Missing artifact org.springframework:spring-context:jar:${org.springframew
让 gradle 构建正常工作( from a previous question related to this one ),安迪·威尔金森(Andy Wilkinson)为我回答,没有问题。正在为
我正在 tomcat 7 中开发网站(spring 3.1.1),但出现错误 ERROR: org.springframework.web.context.ContextLoader - Contex
我在将航类信息保存到 mysql 数据库时遇到错误。请帮助我下面是我的代码: 我已经尝试了所有方法,添加模式和这么多 它不会从字符串转换为日期 控制台日志 2020-05-12 13:19:21.04
我使用intellij创建了一个小型java应用程序,后来我使用“添加框架支持”选项将该项目更新为Maven项目。当我厌倦了在项目上添加 spring jar 文件时,出现以下错误:“没有为 org.
我尝试使用 org.springframework.data.mongodb.core.MongoOperations 从 mongo 集合中查询记录。我在 CompanyTemplRepoImpl
我尝试将 Spring4 与 Hibernate5 一起使用,但出现此错误: org.springframework.orm.jpa.EntityManagerHolder cannot be cas
我是这个论坛的新手。我正在尝试使用 spring 3.2.6 和 tomcat 7.0 制作一个应用程序。我已将所有必需的 jar 添加到 WEB-INF/lib 文件夹中。 DispatcherSe
我在 maven 架构中使用 Spring 框架 4.0.1.RELEASE、OAuth Security 2.0.7.RELEASE,当我编译代码时,出现以下错误。 SEVERE: Exceptio
我正在使用以下指令开发 CRUD Web 应用程序: https://www.javaguides.net/2019/02/spring-boot-2-angular-7-crud-example-t
这个问题已经有答案了: what is the difference in org.springframework.web.servlet.ModelAndView vs org.springfram
我正在尝试将 hibernate 与 spring boot 一起使用。但我收到此错误:org.springframework.orm.jpa.EntityManagerHolder 无法转换为 or
我尝试创建简单的用户登录和注册页面。但我无法使用服务方法创建用户。我有创建新用户的服务。 @Service public class LocalUserDetailsService implement
我用 STS、Roo 和 GWT 创建了一个新项目,并尝试包含 Spring Security。 从那时起,我收到以下错误。有没有人知道出了什么问题?! org.springframework.bea
这些是我正在使用的版本和依赖项 我怀疑版本需要更改但更改为什么,我不确定 springCore : '5.3.3', springjdbc
我是一名优秀的程序员,十分优秀!