Spring笔记收录

参考

Spring专栏系列:https://blog.csdn.net/elim168/category_2665715.html

原理语法类

单例模式的原理以及遇到问题的解决方案

关于Spring,默认情况下controller层是单例模式,即整个服务启动期间只有一个controller对象,但是这个对象满足了所有用户的使用。
https://blog.csdn.net/weiha666/article/details/78670644
为什么单例模式可以支持多并发操作:
https://blog.csdn.net/csj50/article/details/83016508
单例模式的共享对象会因为不同的调用而彼此受到影响的解决方案:
https://blog.csdn.net/darkdragonking/article/details/52367186

FactoryBean介绍

Spring中有两种类型的Bean,一种是普通Bean,另一种是工厂Bean,即FactoryBean,这两种Bean都被容器管理,但工厂Bean跟普通Bean不同,其返回的对象不是指定类的一个实例,其返回的是该FactoryBean的getObject方法所返回的对象。在Spring框架内部,有很多地方有FactoryBean的实现类,它们在很多应用如(Spring的AOP、ORM、事务管理)及与其它第三框架(hibernate丶mybatis丶jpa…)集成时都有体现

BeanFactory 与 FactoryBean的区别, 两个名字很像,所以容易搞混

BeanFactory: 以Factory结尾,表示它是一个工厂类,是用于管理Bean的一个工厂
FactoryBean:以Bean结尾,表示它是一个Bean,不同于普通Bean的是:它是实现了FactoryBean接口的Bean,根据该Bean的Id从BeanFactory中获取的实际上是FactoryBean的getObject()返回的对象,而不是FactoryBean本身, 如果要获取FactoryBean对象,可以在id前面加一个&符号来获取。

作用就是来产生指定类型的bean,比如JPA中,生成指定的实体Factory,该factory用于进一步生成实体

Factoorybean的几个例子:
https://blog.csdn.net/shadow_zed/article/details/72550765?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param

Factorybean接口讲解:
https://blog.csdn.net/zknxx/article/details/79572387

阅读材料:
BeanFactory 简介以及它 和FactoryBean的区别(阿里面试):https://www.cnblogs.com/tiancai/p/9604040.html

BeanPostProcessor实例:自定义注解 + 配置文件注入 + IOC接口

自定义注解(字段级别 + bean生成处理)的demo案例

Spring实战系列(三)-BeanPostProcessor的妙用:https://blog.csdn.net/geekjoker/article/details/79868945>

自定义注解 + 配置文件 + IOC接口:
https://blog.csdn.net/qq_16773855/article/details/88891436?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

常用功能

Spring入参校验较优雅写法

实体类生成时的直接校验:
https://blog.csdn.net/justry_deng/article/details/86571671?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&dist_request_id=1328741.38041.16169883067092943&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control

使用
1)封装成实体类,在类的属性上判断值
@NotNull(message = “名字不能为空”)
private String name;

2)在要验证的方式上加注解:
// 需要在类上加上注解 @Validated
public void f(@NotNull String str) {}

3)AOP自定义切面校验入参

Spring注解增强已有的方法实例

通过注解引入新功能:
https://blog.csdn.net/lyj2018gyq/article/details/82057127?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param

AOP拦截器

https://www.cnblogs.com/duanxz/p/5226304.html
该链接实现了使用注解+AOP编程实现了各个controller层URL调用时候的日志记录。

在AOP当中,获取注解传递进去的值的方法可以参考左侧,获取切面控制的包以及该AOP切面控制的包的设置@point参考:https://www.cnblogs.com/liaojie970/p/7883687.html
在&&@annotation时候,第一次指定注解要给出整个包名

https://segmentfault.com/a/1190000013258647?utm_source=tag-newest
综合了自定义注解与AOP切片,非常nice的demo,实现了数据库缓存的一些东西
implements WebMvcConfigurer 可以实现拦截配置器
为了使得注册的拦截器实现中能够使用gui的service设置的方法,需要注册一个@Bean方法:https://blog.csdn.net/yali_aini/article/details/83721763 参考该博文中的handlerInterceptor拦截器实现
@Bean
public URLHandlerInterceptor setBean2(){
System.out.println(“注入了某个handler”);
return new URLHandlerInterceptor();
}

Spring SPEL使用之–在Java类中使用SPEL

https://blog.csdn.net/jaune161/article/details/51476013?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param

实现文件上传

https://www.cnblogs.com/yangchongxing/p/9290489.html
MultipartFile为上传的文件

SpringBoot加载自定义配置文件的2种方法

https://my.oschina.net/u/4332081/blog/3293498

方法1:@PropertySource,参考:@PropertySource、@Value:读取配置文件与赋值

方法2:EnvironmentPostProcessor.
参考材料:
https://www.cnblogs.com/binarylei/p/10645912.html

spring获取httprequest的4种方式

https://blog.csdn.net/hellozhxy/article/details/80775832?utm_source=distribute.pc_relevant.none-task
httprequest对象介绍:https://www.cnblogs.com/alsf/p/9226072.html
https://blog.csdn.net/QinqinTaylor/article/details/85709698

监听器

https://www.cnblogs.com/duanxz/p/3772654.html

SpringBoot 注入请求公用参数(线程安全)

https://www.jianshu.com/p/dfed57648d1b

ServletContextListener

提供了启动与销毁2个接口,在Spring的生命周期中能够有效控制要加入的线程、变量等的启动与销毁
quartz的集成就参考了这种方式
https://blog.csdn.net/qq_39041134/article/details/81976679

SpringBoot实现系统启动时启动任务

https://www.cnblogs.com/luckyhui28/p/12355334.html

重试机制

https://www.jianshu.com/p/d48911cc1182

https://www.cnblogs.com/juncaoit/p/11398547.html

https://www.cnblogs.com/juncaoit/p/11399991.html

https://blog.csdn.net/a742172349/article/details/106199939

https://blog.csdn.net/u010597819/article/details/108301369

https://www.jianshu.com/p/4e891630d9cc

https://www.cnblogs.com/juncaoit/p/11398547.html

https://blog.csdn.net/u010597819/article/details/108301369

常用注解

@Autowired与@Component:bean注入

由Spring管理,自动注入依赖。不同于new一个对象(new 一个新对象只会得到null),new不借助spring自动生成,无法完成bean中定义的各个操作
https://www.cnblogs.com/Big-Boss/p/10761514.html

@Component + @Autowired配合起来使用才能完成普通类内的注入
实际上等同于普通类 + SpringContext.getBean,但是两个@的配合有单例的效果,该单例由spring容器管控

@Component
public class MessageInternationalization {
@Autowired
private LocaleMessage localeMessage;
}

@Profile实例:集成Swagger

https://blog.csdn.net/russle/article/details/80631981

@RequestParam、@PathVariable:Spring接收参数的2种方式

前端传入list给后端+动态URL传入变量
SpringMVC(三)@PathVariable:https://www.cnblogs.com/FFFFF/p/4624140.html
https://www.cnblogs.com/liuzunli/articles/5497962.html

public CommonResult processApplication(@RequestParam(value = “ids”) List ids, String status, String objectType,
String reason)
SpringMVC开发中遇到的异常1:No primary or default constructor found for interface java.util.List
此异常即为没有写@RequestParam注解

@Component与@Bean的区别

https://blog.csdn.net/qq_38534144/article/details/82414201

@PropertySource、@Value:读取配置文件与赋值

https://www.cnblogs.com/cxuanBlog/p/10927823.html#%E4%B8%89%E3%80%81propertysource%E4%B8%8Evalue%E8%AF%BB%E5%8F%96%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6

@EnableAutoConfiguration启动自动配置

在spring boot的主类的上面添加了@SpringBootApplication注解,该注解中包含了@EnableAutoConfiguration注解,该注解的作用就是开启自动配置,默认的配置项完成绝多大数引入功能/插件的配置

自动配置源码介绍
http://www.monkey1024.com/spring-boot/1817

Spring boot 自动配置 : MultipartAutoConfiguration

https://blog.csdn.net/andy_zhang2007/article/details/89003412

Spring Boot 自动配置 : SecurityAutoConfiguration

https://blog.csdn.net/andy_zhang2007/article/details/90292875?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.channel_param

集成类

集成JMS规范的ActiveMQ

两篇总结得很好的帖子:
https://www.cnblogs.com/JonaLin/p/11506064.html
https://blog.csdn.net/qiangcuo6087/article/details/79041997

集成RabbitMQ

https://www.cnblogs.com/vipstone/p/9950434.html
内容如下:

  1. RabbitMQ介绍以及与其他AMQP消息队列进行对比
  2. 原理图示与简介
  3. 集成代码
    辅助参考(主要是集成代码有关):
    https://www.jianshu.com/p/c0cba2546900

三大框架

ssh
struts spring hibernate
Struts2 Spring Hibernate
ssm(目前最流行的框架)
SpringMVC Spring MyBatis
ssj(Spring springMvc jpa)
Struts2 Spring JPA(过时)
SpringMVC Spring JPA(今天集成的框架)
SpringMVC Spring spring Data JPA(spring的全家桶)

Maven+SSM框架
https://blog.csdn.net/qq_44543508/article/details/100192558

SSJ框架
集成demo:
https://www.jianshu.com/p/ecc0077525b8
JPA各个注解
https://blog.csdn.net/wujiaqi0921/article/details/78789087

Spring + SpringMVC + hibernate
集成demo:
https://blog.csdn.net/weixin_41641941/article/details/91357867?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2alltop_click~default-1-91357867.nonecase&utm_term=spring%E6%95%B4%E5%90%88hibernate

另一个集成demo:
https://www.jianshu.com/p/879bf716295c

hibernate与mybatis比较:
https://blog.csdn.net/eff666/article/details/71332386

SSM框架和SSH框架的区别
https://www.cnblogs.com/shiyh/p/10649748.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值