springboot测试类的执行方式:先根据@SpringBootTest,去查找@SpringBootApplication 启动类,执行启动类,加载默认配置,额外配置(启用fastjson),执行完毕后再执行测试方法。
启用fastjson:
springboot默认使用jackson进行数据处理,json串fastjson。先要导入你的依赖,导入那几个依赖那
我先给大家截一下。
引入jackson fastjson依赖。
启用fastjson:(1)添加fastjson依赖,(2)在启动类中启用fastjson,@Bean注解修饰的方法
```java
//启动fastJson @Bean作用,注册组件 管理对象 等同于<bean></bean>
@Bean
public HttpMessageConverters fastJsonConfigure(){
System.out.println("启用fastJson");
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
//日期格式化
fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
converter.setFastJsonConfig(fastJsonConfig);
return new HttpMessageConverters(converter);
}```