![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Spring-Boot
文章平均质量分 64
库昊天
这个作者很懒,什么都没留下…
展开
-
Jackson常用注解
属性设置@JsonProperty 作用:作用在属性上,用于将JSON数据中的key与POJO对象中的key进行关联,也可以理解为设置属性别名;@JsonProperty("userName")private String name;@JsonIgnore 作用:作用在属性上,忽略某个属性;@JsonIgnoreprivate String name;@JsonForma...原创 2020-03-15 19:27:57 · 207 阅读 · 0 评论 -
Content type 'application/json;charset=UTF-8' not supported
基础 SpringBoot接受到http请求后,会根据content-type来判断请求的数据格式,进而利用HttpMessageConverter将数据解析成特定的类型。对应JSON格式的数据,SpringBoot默认使用jackson进行数据的序列化/反序列化;可能原因原因1:缺少jackson相关的jar包<dependency> <groupId>...原创 2020-03-11 21:57:53 · 10465 阅读 · 0 评论 -
@RequestMapping参数解析
作用 将Http请求映射到具体的方法上;参数path/value:请求需要匹配的URL路径;method:请求需要匹配的方法;headers:请求头中需要包含的字段;consumes:请求的Content-Type需要匹配的范围;produces:返回值的数据格式及编码;...原创 2020-03-11 17:30:01 · 413 阅读 · 0 评论 -
Profile
Profile作用 作用:同一套代码在不同环境读取不同的配置;Profile使用配置如下图所示,各个环境公共的配置写在application.properties中,与环境相关的配置写在对应的application-{xxx}.properties文件中,当程序启动时会优先读取profile设定的环境配置,若读不到才会从application.properties读取;Profile环...原创 2018-09-18 15:37:42 · 416 阅读 · 0 评论 -
SpringBoot单元测试
POM配置&lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt; &lt;scope&gt;t原创 2018-09-19 23:55:19 · 108 阅读 · 0 评论 -
HttpMessageConverters
背景知识Content-Type必须是具体确定的类型,不能包含 *;Accept匹配规则:最明确的优先匹配;@RequestMapping:consumes属性指定处理请求的提交内容类型(Content-Type),produces属性指定返回的内容类型,仅当request请求头中的(Accept)类型中包含该指定类型才返回;HttpMessageConverters作用:Http...原创 2018-10-01 13:38:07 · 4248 阅读 · 1 评论 -
SpringMVC拦截器
HandlerInterceptor所有的拦截器必须实现HandlerInterceptor接口,该接口有三个方法,执行顺序如下:preHandle(…): Before the actual handler is executed;postHandle(…): After the handler is executed;afterCompletion(…): After the com...原创 2018-10-01 16:51:38 · 202 阅读 · 0 评论 -
SpringMVC异常处理
SpringMVC异常处理机制处理机制: DispatcherServlet.doDispatch内部所有异常被捕获,统一由HandlerExceptionResolver链处理,依次遍历判断当前HandlerExceptionResolver是否能够处理,如果能处理则直接处理返回结果,否则交由后续的HandlerExceptionResolver进行处理;public ModelAndV...原创 2018-10-02 15:17:32 · 224 阅读 · 0 评论 -
Lombok使用总结
Lombok简介Lombok 是一种Java实用工具,目的是消除JavaBean中冗余代码,比如getter/setter、toString、hashCode等等,通过注解达到相同目的;使用步骤1. 添加maven依赖非SpringBoot环境&amp;lt;dependency&amp;gt; &amp;lt;groupId&amp;gt;org.projectlombok&amp;lt;/groupId&a原创 2018-09-20 21:29:17 · 727 阅读 · 0 评论 -
生成配置元数据
配置元数据配置元数据是指对application.properties或application.yml文件中的配置属性进行描述的信息。Spring Boot jars include metadata files that provide details of all supported configuration properties. The files are designed to ...原创 2018-09-26 21:47:16 · 1377 阅读 · 0 评论 -
自定义Starter
组成Autoconfigure:负责bean的自动装配;Starter:负责相关Jar包的集中管理,及依赖Autoconfigure;You may combine the auto-configuration code and the dependency management in a single module if you don’t need to separate thos...原创 2018-09-27 19:36:53 · 407 阅读 · 0 评论 -
文件上传
MultipartResolver作用: 当接收到content-type类型为multipart/form-data的POST请求时,将HttpServletRequest包装成MultipartHttpServletRequest,以便能够使用MultipartFile入参。使用注意: bean的名称必须为"multipartResolver";具体实现: Apache的 Commons...原创 2018-09-30 15:07:03 · 149 阅读 · 0 评论 -
SpringBoot Logback扩展
日志配置诉求同一个配置文件,不同环境可以配置不同的日志级别和存储路径;当为特定的环境时,某些特定的配置可以生效;SpringBoot Logback扩展 SpringBoot对Logback进行了一定扩展,用户可以在logback-spring.xml中使用这些高级特性;变量引用 日志配置文件中,可以引用配置文件中的变量,比如日志级别和路径等; //source为配置文...原创 2019-09-09 21:14:10 · 475 阅读 · 0 评论 -
Spring Boot配置文件
配置获取顺序 多环境配置命名规范: application-{profile}.properties,profile表示不同环境,如日常、预发和线上等; 文件路径:与application.properties相同; 环境指定:在application.properties文件中进行设定:spring.profiles.active={profile}; 使用说明:...原创 2018-07-04 19:19:16 · 203 阅读 · 0 评论 -
Starter Pom
作用 在POM文件添加场景所需的Starter Pom,Spring Boot会自动配置相应的Bean,不需要XML配置文件;Spring Boot内置的Starter Pom Spring Boot内置的Starter Pom统一集中在spring-boot-autoconfigure包中,如下图所示: 关键技术点META-INF/spring.factories中需...原创 2018-07-04 12:25:05 · 415 阅读 · 0 评论 -
Spring Boot日志配置
日志体系 Spring Boot 使用commons-logging作为日志接口,目前支持Log4J2、Logback和JUL( Java Util Logging) 三种实现方式,如下图所示: spring-boot-starter-logging作用:使用Logback日志框架; 实现原理:如果存在slf4j接口,则将其桥接到commons-logging;使用L...原创 2018-07-03 17:00:49 · 250 阅读 · 0 评论 -
FatJar技术
概念 将一个jar及其依赖的三方jar全部打到一个包中,这个包即为FatJar。作用 作用: Jar包隔离,避免Jar冲突。打包方式maven-shade-plugin插件;spring-boot-maven-plugin插件(Spring Boot打包插件);嵌套Jar资源加载方案 思路:扩展Jar URL协议+定制ClassLoader;扩展Ja...原创 2018-06-21 19:19:42 · 6312 阅读 · 0 评论 -
代理启动Launcher
整体过程Spring Boot打包插件将启动类设为org.springframework.boot.loader.JarLauncher;JarLauncher内部通过反射调用应用程序入口类,启动应用;Launcher类体系 JarLauncher 、WarLauncher 、PropertiesLauncher代表了Spring Boot的三种代理启动方式。Step1: ...原创 2018-06-22 10:45:55 · 1230 阅读 · 0 评论 -
获取FatJar资源URL
背景知识:Archive Archive表示归档文件,通常为tar/zip等格式压缩包,Jar包为zip格式归档文件。SpringBoot抽象了Archive的概念,分为JarFileArchive(Jar包)和ExplodedArchive(文件目录)。 获取嵌套资源过程获取当前Jar包代表的Archive;根据过滤条件筛选出当前Jar包嵌套的资源;获取当前Jar包代表...原创 2018-06-22 14:04:44 · 513 阅读 · 0 评论 -
@ComponentScan
作用 指定扫描路径(定义bean的class文件所在路径);工作原理 要创建Bean的class文件集合形成扫描路径,传入@ComponentScan,然后由ComponentScanAnnotationParser或者ClassPathBeanDefinitionScanner对扫描路径下的class文件扫描解析,如下图所示: ClassPathBeanDefinition...原创 2018-06-29 18:00:11 · 1265 阅读 · 0 评论 -
@Import
作用 @Import 被用来整合所有在@Configuration注解中定义的bean配置,类似于将多个XML配置文件导入到单个XML文件的情形。使用 与@Configuration配合使用,如下所示:@Configuration@Import({JavaConfigA.class,JavaConfigB.class})public class ParentConfig...原创 2018-06-30 17:32:49 · 234 阅读 · 0 评论 -
@Conditional
作用 根据特定条件来控制Bean的创建行为,比如说只有某个Bean被创建才会创建另外一个Bean。使用 @Conditional元数据为实现Condition接口类的集合,matches返回true则创建Bean。可以使用在类型和方法上,与其它创建Bean的注解配合使用。类型级别,可以在@Component 或是 @Configuration类上使用;方法级别,可以用在@B...原创 2018-06-30 17:51:31 · 268 阅读 · 0 评论 -
@Configuration
作用 声明当前类是一个配置类,相当于一个Spring的XML配置文件,与@Bean配合使用。 Instead of using the XML files, we can use plain Java classes to annotate the configurations by using the @Configuration annotation. If you an...原创 2018-07-01 09:12:14 · 6210 阅读 · 0 评论 -
组合注解与元注解
概念元注解: 可以注解到别的注解上的注解;组合注解:被注解的注解;组合注解好处简单化注解配置,一个组合注解可以代表多个有特定属性值的元注解;提供了很好的扩展性,可以根据实际需要灵活的自定义注解。@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documentedpublic @inter...原创 2018-07-01 11:38:04 · 1276 阅读 · 0 评论 -
微服务架构选型:Dubbo VS Spring Cloud
定位 Dubbo 的定位始是RPC 框架,而 Spring Cloud 的目标是微服务架构下的一站式解决方案。在架构功能角度, Dubbo是Spring Cloud的一个子集,具体对比如下: RPC vs REST代码侵入性。对于RPC调用方式,服务提供方和调用方之间需要强依赖接口,存在代码级别的入侵;对于REST调用方式,服务提供方和调用方之间只有约定,没有代码上的侵入;...原创 2018-07-08 15:54:47 · 716 阅读 · 0 评论 -
微服务/ Spring Boot / Spring Cloud
微服务 微服务是一种“化整为零、分而治之”的思想。具体而言,微服务提倡将单一应用程序划分成一组小的服务,每个服务运行在其独立的进程中,服务与服务间采用轻量级的通信机制互相沟通(通常是基于 HTTP 的 RESTful API)。每个服务都围绕着具体业务进行构建,并且能够被独立地部署到生产环境、类生产环境等。 “Microservices”概念的提出者Martin Fowler的描述如下...原创 2018-07-08 16:33:22 · 240 阅读 · 0 评论 -
SpringApplication构造过程分析
构造函数设置Spring容器的初始化逻辑ApplicationContextInitializer;设置Spring容器的监听器ApplicationListener;获取启动类的Class对象;public SpringApplication(ResourceLoader resourceLoader, Class&amp;lt;?&amp;gt;... primarySources) { ...原创 2018-07-02 10:18:56 · 247 阅读 · 0 评论 -
自动配置@EnableAutoConfiguration
作用 根据pom中添加的jar依赖自动配置Spring,比如添加spring-boot-starter-web,Spring Boot会自动添加Tomcat和Spring MVC相关配置。自动装配原理 @EnableAutoConfiguration实现的关键在于引入了AutoConfigurationImportSelector,其核心逻辑为selectImports方法,逻辑大...原创 2018-07-02 19:56:09 · 4359 阅读 · 0 评论 -
打包可执行Jar
打包插件 <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-p...原创 2018-06-21 17:07:29 · 144 阅读 · 0 评论