
-
踩坑合集 -
数字生活 1篇 -
生活 -
初学Mybatis 3篇 -
狼人杀plus微信小程序开发全记录
5篇 -
java 30篇 -
git 1篇 -
mysql 6篇 -
linux 6篇 -
mybatis 3篇 -
nginx 2篇 -
redis 3篇 -
springboot 4篇 -
docker 5篇 -
技术宅拯救世界 7篇 -
开发工具 7篇 -
jquery 1篇 -
算法 3篇 -
系统使用 -
ajax 4篇 -
c -
json 3篇 -
杂文 1篇 -
微信小程序 3篇 -
钉钉开发 1篇 -
开发知识积累 3篇 -
andorid 6篇 -
struts2 3篇 -
debug 4篇 -
oracle 5篇 -
重学java 5篇 -
python3 1篇 -
postgre -
gitlab ci 1篇 -
macOS每日记录 3篇

- 最近
- 文章
- 代码仓
- 视频


system class loader和appclassloader
能不能把这个图贴出来看看?
---
接题主提出的图,继续回答:
首先要知道在JDK中并没有SystemClassLoader这个类。
其次,Java虚拟机规范中指出,Class Loader分为Bootstrap Class Loader以及User-defined Class Loader,其中Bootstrap Class Loader是由Java虚拟机使用C++实现的,没有对应的Java对象。
所谓User-defined Class Loader,其实也没有叫这个名称的Java对象,这里是一种泛称,直译过来为用户定义的Class Loader,对应JDK中的Java对象是java.lang.ClassLoader及其子类,除此之外,JDK中还提供了sun.misc.Launcher.ExtClassLoader以及sun.misc.Launcher.AppClassLoader。
由于CSDN对Markdown语法支持比较差,并且我之前有写过相关的博客,所以这里我就不展开了,需要的话,你可以直接访问https://blog.baofeidyz.com/%E7%B1%BB%E7%9A%84%E5%8A%A0%E8%BD%BD-%E9%93%BE%E6%8E%A5%E5%92%8C%E5%88%9D%E5%A7%8B%E5%8C%96-%E5%9F%BA%E4%BA%8EJava-1.8/
查看。
关于Java虚拟机规范的描述,可以访问https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-5.html 查看。
由于图片中的上下文,我并不是很清楚,所以没有直接回答你的问题,希望你能从我的答复中找到答案。
为什么序列化LocalDateTime失效?
我觉得你这个做法有点三不像,为什么这样说呢?
你增加了一个类,并实现了WebMvcConfigurer,这一点是正确的,但是你又不去@Override相关的方法。我在网上搜到一些关于这个类的说明,你可以做一个简单的参考https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/servlet/config/annotation/WebMvcConfigurer.html
关于这个问题的解决方案:
package com.baofeidyz.springbootdemo.config;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import static java.time.format.DateTimeFormatter.ofPattern;
@Configuration @EnableWebMvc public class JacksonAutoConfiguration implements WebMvcConfigurer {
@Value("${spring.jackson.date-format:yyyy-MM-dd HH:mm:ss}") private String localDateTimePattern;
@Value("${spring.jackson.date-format:yyyy-MM-dd}") private String localDatePattern;
@Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = new ObjectMapper();
JavaTimeModule javaTimeModule = new JavaTimeModule();
javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer());
javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer());
javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer());
javaTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer());
objectMapper.registerModule(javaTimeModule);
converter.setObjectMapper(objectMapper);
converters.add(converter);
converters.add(new StringHttpMessageConverter(StandardCharsets.UTF_8));
}
public class LocalDateTimeSerializer extends JsonSerializer<LocalDateTime> {
@Override public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers)
throws IOException {
gen.writeString(value.format(ofPattern(localDateTimePattern)));
}
}
public class LocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {
@Override public LocalDateTime deserialize(JsonParser p, DeserializationContext deserializationContext)
throws IOException {
return LocalDateTime.parse(p.getValueAsString(), ofPattern(localDateTimePattern));
}
}
public class LocalDateSerializer extends JsonSerializer<LocalDate> {
@Override public void serialize(LocalDate value, JsonGenerator gen, SerializerProvider serializers)
throws IOException {
gen.writeString(value.format(ofPattern(localDatePattern)));
}
}
public class LocalDateDeserializer extends JsonDeserializer<LocalDate> {
@Override public LocalDate deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
return LocalDate.parse(p.getValueAsString(), ofPattern(localDatePattern));
}
}
}
此外,我相信这个问题应该还有别的解决方案,如果你找到了,也请告诉我一下,多谢










