zoukankan      html  css  js  c++  java
  • 课时1:Spring环境搭建、STS工具、第一个Spring程序

    .1)概要以及介绍

      1.2002 作者 Rod Jonnon 发布了一篇文章<Expoer One-toOne j2eedvelopment and Design>

      2.2003年根据这篇文章产生了一些感悟 产生了Spring

      3.spring最基础的核心AOP IOC

      4.经过了18年的的洗礼衍生出很多框架 Spring Data,Spring Boot ,Spring Cloud,Spring Framework,Springsocial

    .2)IOC:控制反转 (DI:依赖注入)

      1.搭建Spring的环境

        1.1 导入spring的依赖jar包

      <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context</artifactId>
          <version>4.3.9.RELEASE</version>
        </dependency>
         <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
        <dependency>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
          <version>1.18.10</version>
          <scope>provided</scope>
        </dependency>

        1.2 编写配置文件

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    
    </beans>

      2.开发Spring程序(IOC)

        2.1 编写配置文件

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <bean id="student" class="net.bdqn.hbz.pojo.Student">
        <property name="stuno" value="1"></property>
        <property name="stuName" value="zs"></property>
        <property name="stuAge" value="24"></property>
    </bean>
    </beans>

          2.1.1 id:唯一标识符 class:指定类的路径

          2.1.2 property标签 :代表该class的属性

            2.1.2.1 name:属性名称

            2.1.2.1 value :属性值

        2.2 通过bean的id来获取一个对象

    //创建上下文对象
            ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
            //通过bean的id来获取对象
            Student student =(Student) context.getBean("student");
            System.out.println(student);

      3.这样写的一些分析以及好处

        3.1 不需要new

        3.2 对象属性的赋值

        3.3 在applicationContext.xml中产生的对象,被spring放入了一个 称为Spring IOC容器里面

  • 相关阅读:
    设计模式-外观模式
    多线程面试笔试题-1
    final 关键字
    java 继承 初始化顺序
    java内部类
    Python-面向对象-静态方法
    接口自动化测试框架搭建
    使用yaml设计测试用例进行单接口测试
    数据驱动测试--对excel文件的操作
    TCP协议详解
  • 原文地址:https://www.cnblogs.com/thisHBZ/p/12484316.html
Copyright © 2011-2022 走看看