编程原则

springboot+redis 缓存

MyBatis

Redis

任务

当我们讨论 Java 程序的启动,尤其是 public static void main(String[] args) 方法,我们实际上是在探讨 Java 程序的入口点。这个方法有几个关键要素,每个都有其特定的原因和目的:

  1. 为什么是静态(static)?
  2. 为什么是公开的(public)?
  3. 为什么没有返回值(void)?
  4. 为什么需要字符串数组参数(String[] args)?

在 Spring Boot 应用中,情况稍有不同但基本原理相同:

  1. Spring Boot 的启动过程:

  2. 为什么使用 SpringApplication.run?

    spring中的bean四个作用域

    Spring支持以下四种主要的Bean作用域:

    1. Singleton(单例):

      • 默认的作用域,一个Spring容器中只存在一个Bean实例。每次请求都返回同一个实例。在XML配置中,可以使用**<bean>标签的scope属性指定为singleton**。
      
      <bean id="exampleBean" class="com.example.ExampleBean" scope="singleton"/>
      
    2. Prototype(原型):

      • 每次请求都创建一个新的Bean实例。在XML配置中,可以使用**<bean>标签的scope属性指定为prototype**。
      
      <bean id="exampleBean" class="com.example.ExampleBean" scope="prototype"/>
      
    3. Request(请求):

      • 在Web应用中,每次HTTP请求都会创建一个新的Bean实例,该作用域仅在使用Spring的Web-aware ApplicationContext时才有效。在XML配置中,可以使用**<bean>标签的scope属性指定为request**。
      
      <bean id="exampleBean" class="com.example.ExampleBean" scope="request"/>
      
    4. Session(会话):

      • 在Web应用中,每个HTTP会话创建一个Bean实例,该作用域同样仅在使用Spring的Web-aware ApplicationContext时才有效。在XML配置中,可以使用**<bean>标签的scope属性指定为session**。
      
      <bean id="exampleBean" class="com.example.ExampleBean" scope="session"/>
      

    这些作用域允许开发者按照应用程序的需求来配置Bean的生命周期。默认情况下,Bean是单例的,但根据业务需求,可以选择使用原型、请求或会话作用域。