1、 spring boot默认使用json的解析框架Jackson.
2、 使用fastjson,需要引入fastjson依赖包:
A、 我们需要在pom.xml中引入相应的依赖;
B、 需要在App.java中将fastJson添加到转换器中,使用@bean注解
@Bean
public HttpMessageConverters fastJsonHttpMessageConverters() {
//创建fastjsonconverter
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
//格式化fastjsonconfig
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
fastConverter.setFastJsonConfig(fastJsonConfig);
HttpMessageConverter<?> converter = fastConverter;
return new HttpMessageConverters(converter);
}
3、 Spring devtools热部署,引入包:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
写plugin:
<!-- 热部署 -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
热部署出现的问题:开始使用1.4.1版本的spring boot,配置的热部署不起作用,将版本换成1.3.3可以实现。
4、 全局异常捕捉:
@ControllerAdvice
public class GlobalDefaultExceptionHandler {
@ExceptionHandler(Exception.class)
@ResponseBody
public String defaultExceptionHandler(HttpServletRequest req,Exception e) {
return "对不起,服务器繁忙,请稍后再试!";
}
}
5、 Spring boot server在application.properties中的配置