spring框架(spring全家桶)

spring FrameWork

springBoot+springCloud+springCloud Data Flow

一:spring的两大核心机制:

  • IoC :工厂模式
  • AOP:代理模式

1:Ioc

Ioc是Spring是框架的灵魂,控制反转。

Student student = new Student();

lombok 可以帮助开发这者自动生成get set 方法..

在idea中使用必须安装插件

@Data注解

@AllArgsConstructor注解全参的构造

@NoArgsConstructor注解构造无参

设置mavend的版本太低:

  1. file - projectStructure.. - Modules - Language Level:jdk8以上
  2. File --> Settings --> Build,Execution,Deployment --> Compiler --> java Compiler

开发过程:

  1. 创建Maven工程,pom.xml导入依赖。



    org.springframework
    spring-context
    5.2.3.RELEASE

    1. 在resources路径下创建spring.xml




      3.IoC容器通过读取spring.xml配置文件,加载bean标签来创建对象
      4.调用API来获取IoC中的已经创建的对象
      //传统的开发方式是手动开发对象
      // Student a = new Student();
      // System.out.println(a);
      //IoC容器自动创建对线,开发者只需要取出对象即可
      ApplicationContext applicationContext =new ClassPathXmlApplicationContext("spring.xml");
      Student student = (Student)applicationContext.getBean("student");
      System.out.println(student);
      }

IoC容器创建Bean的两种方式:

  • 无参构造

    给成员变量赋值(原理是利用set 方法修改的)



    <property name="age"value="20">

    IoC取对象:

    • id取
      Student student = (Student)applicationContext.getBean("student");
    • 实体类的实例类取
      Student student = (Student)applicationContext.getBean(Student.class);

    实体类有多个抛异常

  • 有参构造

取对象:

 ApplicationContext applicationContext =new ClassPathXmlApplicationContext("spring.xml");
        Student student = (Student)applicationContext.getBean("student1");
//        Student student = (Student)applicationContext.getBean(Student.class);
        System.out.println(student);

bean中包含特殊字符可以:]]>

<bean id ="classes" class="com.southwind.entity.Classes">
    <property name="id" value="1"></property>
    <property name="name">
       <value><![CDATA[<一班>]]></value> 
    </property>
</bean>
posted on 2022-06-23 21:08  Steam残酷  阅读(67)  评论(0)    收藏  举报