
spring
tszxlzc
这个作者很懒,什么都没留下…
展开
-
SpringBoot自动配置注解原理解析
自动配置开始于 @SpringBootApplication@SpringBootApplication 类定义@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documented@Inherited@SpringBootConfiguration@EnableAutoConfiguration@Com...原创 2019-12-09 22:20:24 · 242 阅读 · 0 评论 -
spring boot 配置文件加载
加载是在ConfigFileApplicationListener监听器中加载的监听逻辑public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ApplicationEnvironmentPreparedEvent) { onApplicationEnvironmentPrepar...原创 2019-12-08 21:38:37 · 183 阅读 · 0 评论 -
spring boot加载bean定义的过程
不同的spring boot应用加载bean定义的过程是不同的,本例是servlet应用程序加载bean定义的过程,并顺带了mybatis 的mapper加载放一张图,我喜欢从头梳理整个流程,所以main方法一步步跟进来的...原创 2019-12-08 19:39:42 · 230 阅读 · 0 评论 -
学习spring中的SPI机制
找一个 spring 使用SPI机制的入口,org.springframework.beans.factory.xml.BeanDefinitionParserDelegate#parseCustomElement(org.w3c.dom.Element, org.springframework.beans.factory.config.BeanDefinition) 这个方法是在解析xml配置...原创 2019-10-22 23:12:10 · 1775 阅读 · 0 评论 -
Could not initialize class com.sendinfo.usr.util.SysCacheUtil 问题解决
描述现象,启动报错Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mqServiceFactory' defined in class path resource [applicationContext.xml]: Instantiation ...原创 2019-10-22 15:58:22 · 1807 阅读 · 0 评论 -
问afterPropertiesSet和初始化方法那个先执行
背景:InitializingBean 接口有个afterPropertiesSet方法用来在设置完所有bean属性后调用bean配置中有个init-method的配置问 这两个方法的执行顺序去源码中看方法org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#initializeBean...原创 2019-06-14 15:30:47 · 7271 阅读 · 1 评论 -
spring boot自动化配置druid + mybatis
先添加maven配置 <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId&g...原创 2019-04-08 14:51:48 · 539 阅读 · 0 评论 -
Spring的五种依赖注入方式
1. 目前使用最广泛的 @Autowired:自动装配@Autowired 注解可以加在字段、构造函数、setter方法或者配置方法(有一个或多个参数)上2. setter 方法注入3. 构造器注入4. 静态工厂的方法注入5. 实例工厂的方法注入具体例子参考博客 https://blog.youkuaiyun.com/shadow_zed/article/details/72566611...原创 2019-03-13 19:25:35 · 303 阅读 · 0 评论 -
controller 异常统一处理的四种方式,透过这四种方式看spring注解的派生性
1.当在一个Controller中任何一个方法发生异常,一定会被这个方法拦截到。由于这里controller是@RestController 注解的,等于每个方法已经添加了@ResponseBody注解,下面是@RestController 的源码@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documented...原创 2019-03-07 17:32:31 · 1662 阅读 · 0 评论 -
Spring源码解析 – @Configuration配置类是怎么生效的,并将bean解析到spring容器中
首先被@Configuration注解的类是由ConfigurationClassPostProcessor bean后处理器来处理的,下面看一下ConfigurationClassPostProcessor bean后处理器是怎么被加载到的,下面时序图说明spring容器从启动倒注册ConfigurationClassPostProcessor bean后处理器的过程2.Configura...原创 2019-03-04 13:59:33 · 2631 阅读 · 0 评论 -
spring boot EnableConfigurationProperties ConfigurationProperties 怎么配合使用的
先看我的demo实现第一步: 配置ConfigurationProperties属性@ConfigurationProperties(prefix = "redis.proxy")@Getter@Setterpublic class RedisProperties { /** 服务器列表*/ private List&lt;String&gt; configServerList;...原创 2019-03-06 21:36:58 · 819 阅读 · 0 评论 -
spring boot 自动配置原理:找到不同组件的配置文件、配置配置文件的属性文件
spring boot 默认会配置的配置文件 SpringBootApplication注解是程序入口@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documented@Inherited@SpringBootConfiguration@EnableAutoConfiguration //Sp...原创 2019-03-05 09:15:01 · 460 阅读 · 0 评论 -
spring源码分析(一)lazy-init 在Spring中是怎么控制加载的
lazy-init为false,spring容器启动时进行预实例化lazy-init为true,spring容器启动时懒加载拥有改属性的bean,不进行预实例化以下源码可以重点看注释部分IOC阶段,将bean的配置信息解析成BeanDefinition,并放入map中解析BeanDefinition的方法org.springframework.beans.factory.xml.Bean...原创 2019-01-16 11:30:17 · 359 阅读 · 0 评论 -
ApplicationContextAware的setApplicationContext方法是什么时候执行的
ApplicationContextAware的setApplicationContext方法时什么时候执行的可以肯定的是在从容器中getbean的过程中调用的,简单说下几个主要流程getbean到调用bean后处理器 getbean的流程参见下图,主要参考标红字体部分 从图中可以看出,最后会调用initializeBeanf方法又会调用applyBeanPostProcesso...原创 2018-09-16 10:00:08 · 16690 阅读 · 2 评论 -
[springmvc]返回ModelAndView,视图解析不到jsp,而是去解析“'请求路径'+ ‘.jsp’”
我要求请求http://127.0.0.1:8080/index/login 结果确去请求/WEB-INF/pages/index/login.jsp 我的controller如下import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMa原创 2016-03-07 15:45:31 · 9790 阅读 · 2 评论 -
spring service方法里有两个save时的同步问题
如下代码,想要使两个save方法保持一致性,即第一个save方法和第二个save方法要么同时生效,要么同时不生效。只需要像这样将commonDao的两个save方法在service的方法中调用即可,已经通过测试验证。因为spring 事务是对savePayRecord方法进行的事务管理public void savePayRecord(PayInfoVO payInfo) { // T原创 2015-09-10 11:20:50 · 3226 阅读 · 0 评论