Spring 笔记自整理01

这篇博客介绍了Spring框架的基础知识,包括搭建Spring项目的过程和Spring的核心特性。讲解了IoC(控制反转)和DI(依赖注入)的区别,以及BeanFactory和ApplicationContext接口的作用。此外,还探讨了Spring配置bean实例化的方式以及Spring AOP中的关键概念,如切面、连接点、通知、切入点等。
摘要由CSDN通过智能技术生成

Spring 笔记01

1. 搭建Spring项目
(1)创建项目,加载依赖

<ependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.3.7.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.3.7.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>4.3.7.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>4.3.7.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-expression</artifactId>
        <version>4.3.7.RELEASE</version>
    </dependency>


    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
    </dependency>
</dependencies>

(2)在resources中新建配置文件
文件名官方推荐------applicationContext.xml
新建方式:在resources右击->New->XML Configuration File->Spring Config然后会出现提示
点击Configure application context->create new application context->ok就完成啦!

2. Spring框架特征实例
(1) 工厂分为静态工厂和非静态工厂
创建对象的实例:

public class PeersonFactory {
   
    //创建person的静态方法
    public static Person createPerson(){
   
        System.out.println("通过静态工厂创建了对象");
        return new Person(123,"小乔","女");
    }
}
public class NoStaticPeersonFactory {
   
    //创建person的非静态方法
    public Person createPerson(){
   
        System.out.println("通过非静态工厂创建了对象");
        return new Person(123,"小乔","女");
    }
}

<!--name="person,person2"相当于小名
可以取多个值 但是不能重复
id:不可以重复且不能使用特殊字符
lazy-init表示对象的加载时机(true(使用对象的时候才创建);false(spring框架一启动就加载))-->
<!--方式1.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值