1. Spring profile
  2. 条件化的 bean声明
  3. 自动装配和歧义性
  4. bean的作用域
  5. Spring表达式语言

一.Spring profile

  • 使用Java来生成,需要**profile

05----------高级装配

  • 在XML中配置

05----------高级装配

  • **profile,需要使用spring.profiles.active和spring.profiles.default,如果设置了spring.profiles.active,那么它的值决定了哪个profile是**的

如果没有设置,则会区查找spring.profiles.default,如果都灭有,spring会去创建没有定义在profile中的bean

一般在web.xm中使用DispatcherServlet初始化:

05----------高级装配

按照这种方式,默认使用spring.profiles.default,如果需要将应用部署到QA,生产后其他环境,可以设置spring.profiles.active即可,因为active优先级大于default。

二.自动装配的歧义性

05----------高级装配

这样spring无法确认装配哪个,使用@Primary或使用限定符qualifier

05----------高级装配

bean的作用域,可以使用@Scope来声明哪种类型,默认使用单例SIngleton

05----------高级装配

注入外部的值:使用@PropertySource注解和Environment

05----------高级装配

 

相关文章:

  • 2021-06-20
  • 2022-01-05
  • 2021-12-06
  • 2021-12-06
  • 2021-12-06
  • 2021-06-04
  • 2022-01-21
  • 2022-12-23
猜你喜欢
  • 2021-12-06
  • 2021-06-24
  • 2021-08-04
  • 2022-12-23
  • 2022-02-08
  • 2022-02-11
相关资源
相似解决方案