文章目录

  • Spring工厂接口
    • BeanFactory接口
    • ApplicationContext 接口
  • Spring的bean管理的两种方式:
    • 3 种实例化bean的方式(xml)
      • 通过构造方法创建bean实例案例
      • 使用静态工厂方法创建bean实例案例
      • 使用实例工厂方法创建bean实例案例
    • Spring(DI依赖注入)属性注入(xml)
      • 构造器注入
      • setter设值注入
      • p命名空间注入
      • SpEL注入
    • 复杂类型的属性注入(xml)
      • 简单类型
      • 对象类型
      • List、Map、Set 、Array 和 Properties
  • 注解配置实例化bean
  • 注解实现属性注入
    • 普通类型属性注入
    • 对象类型属性注入
    • 使用@Autowired + @Qualifier进行装配
    • 使用@Resource进行装配
    • 其它类型注解
      • bean生命周期的注解
      • bean作用范围的注解
  • 注释是否比配置Spring的XML更好?
  • XML和注解整合开发

Spring工厂接口

  • BeanFactory 接口
  • ApplicationContext 接口
BeanFactory接口
  • BeanFactory接口 作为Spring工厂的顶层接口,它采取延迟加载,只有在第一次调用getBean()时才会初始化bean对象

  • BeanFactory 作为Spring框架早期的创建Bean对象的工厂接口,我们也可以通过它来获取到bean对象

@Test /*使用 @Test注解后,可以不用在main方法中进行测试,提高测试效率*/
public void demo11(){// 创建spring工厂BeanFactory beanFactory=new XmlBeanFactory(new ClassPathResource("spring.xml"));
//  BeanFactory beanFactory=new XmlBeanFactory(new FileSystemResource("E:/ideaUI/SpringConfig/spring.xml"));// 通过工厂获得类对象Food food= (Food) beanFactory.getBean("food");}
ApplicationContext 接口
  • ApplicationContext接口是BeanFactory的子接口,在BeanFactory的基础上扩展了 国际化处理、自动装配等功能,现在的开发基本都是使用ApplicationContext

  • ApplicationContext 初始化对象的时机不同于 BeanFactory,它在加载Spring配置文件交给容器管理时,就会对配置文件中的所有bean进行实例化

  • ApplicationContext 有两个实现类

    • ClassPathXmlApplicationContext (加载类路径下的Spring配置文件
    • FileSystemXmlApplicationContext (加载本地磁盘中的Spring配置文件

ClassPathXmlApplicationContext

@Test /*使用@Test注解后,可以不用在main方法中进行测试,提高测试效率*/
public void demo1(){// 创建spring工厂ApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring.xml");// 通过工厂获得类对象ImplClass implClass= (ImplClass) applicationContext.getBean("implClass");System.out.println(implClass);
}

FileSystemXmlApplicationContext

@Test /*使用@Test注解后,可以不用在main方法中进行测试,提高测试效率*/
public void demo2(){// 创建spring工厂ApplicationContext applicationContext=new FileSystemXmlApplicationContext("E:/ideaUI/SpringConfig/spring.xml");// 通过工厂获得类对象ImplClass implClass= (ImplClass) applicationContext.getBean("implClass");System.out.println(implClass);
}

Spring的bean管理的两种方式:

  • 通过 xml 方式管理bean

  • 通过 注解(annotation)方式管理bean

基于 xml 方式的 bean 管理

我们把类交给spring ,spring就会帮我们生成这个类的实例,那么它是如何生成的呢?

3 种实例化bean的方式(xml)
  • 使用构造器创建bean(默认使用无参构造器)

    • 无参构造方法
    • 有参构造方法
  • 使用静态工厂方法创建bean(简单工厂模式)

  • 使用实例工厂方法创建bean(工厂方法模式)

通过构造方法创建bean实例案例

一、通过无参构造方法创建bean实例

public class Bean1 {/*不定义构造方法时,会默认创建一个无参构造方法(不可见),定义了构造方法后,就不会再默认创建无参构造方法所以,创建了有参构造方法后,若还想通过无参构造方法创建bean实例,需再创建一个无参构造方法*/public Bean1() {System.out.println("通过无参构造方法的方式创建bean实例. . .");}
}
<!--1.1、通过无参构造方法创建bean实例-->
<bean id="bean1" class="com.cd4356.demo2.Bean1"/>
@Test
public void demo1(){ApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring.xml");Bean1 bean1= (Bean1) applicationContext.getBean("bean1");
}

二、通过有参构造方法创建bean实例

public class Bean2 {public Bean2(String name, String way) {System.out.println(name+"通过"+way+"创建bean实例. . ."+"===="+age);}
}

注意:通过有参构造方法创建bean实例时,需通过<constructor-arg>标签为所有参数赋值,不然无法通过编译(报错)

<!--1.2、通过有参构造函数创建Bean实例-->
<bean id="bean2" class="com.cd4356.demo2.Bean2"><constructor-arg name="name" value="spring"/><constructor-arg name="way" value="有参构造方法"/>
</bean>
@Test
public void demo2(){ApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring.xml");Bean2 bean2= (Bean2) applicationContext.getBean("bean2");
}
使用静态工厂方法创建bean实例案例
public class Bean3 {private String id;private String cource;private double time;public Bean3(String id, String cource, double time) {this.id = id;this.cource = cource;this.time = time;}@Overridepublic String toString() {return id+","+cource+","+time;}
}
public class Bean3Factory {/*静态工厂,就是在工厂类当中提供了一个静态的方法,返回一个类的实例对象*/public static Bean3 createBean3(){return new Bean3("1706050401","高等数学",1.5);}
}
<!--第二种: 通过静态工厂方法创建Bean实例-->
<bean id="bean3" class="com.cd4356.demo3.Bean3Factory" factory-method="createBean3"/>
@Test
public void demo3(){ApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring.xml");Bean3 bean3= (Bean3) applicationContext.getBean("bean3");System.out.println(bean3);
}

对比有参构造方式,当类中含有多个属性,我们要通过有参构造方式创建bean实例,就需要在创建bean时通过<constructor-arg>将构造方法的所有参数初始化,而使用静态工厂或实例工厂的方式,直接返回一个带参构造对象即可。

使用实例工厂方法创建bean实例案例
public class Bean4 {private String id;private String cource;private double time;public Bean4(String id, String cource, double time) {this.id = id;this.cource = cource;this.time = time;}@Overridepublic String toString() {return id+","+cource+","+time;}
}
public class Bean4Factory {public Bean4 createBean4(){return new Bean4("170701","职业英语",4.5);}
}
<!--第三种: 通过实例工厂方法创建Bean实例-->
<bean id="bean4Factory" class="com.cd4356.demo4.Bean4Factory"/>
<bean id="bean4" factory-bean="bean4Factory" factory-method="createBean4"/>
@Test
public void demo4(){ApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring.xml");Bean4 bean4= (Bean4) applicationContext.getBean("bean4");System.out.println(bean4);
}

DI的基本概念:spring在帮我们创建类对象的过程中,将类所依赖的属性或对象设置进来

Spring(DI依赖注入)属性注入(xml)
  • 构造器注入

  • setter设值注入(最常用

  • p命名空间注入

  • SpEL注入

构造器注入
  • 通过构造方法注入bean的属性值或依赖的对象,保证了bean实例在实例化后就可以使用了

  • 构造器注入,在Spring中配置文件中,通过<constructor-arg>元素设置注入的属性

public class User {private String name;private char sex;public User(String name, char sex) {this.name = name;this.sex = sex;}@Overridepublic String toString() {return name+","+sex;}
}
<!--第一种: 构造器注入-->
<bean id="user" class="com.cd4356.demo5.User"><constructor-arg name="name" value="张三"/><constructor-arg name="sex" value="男"/>
</bean>
setter设值注入
  • setter方法注入,在Spring中配置文件中,通过<property>元素设置注入的属性
public class User {private String name;private char sex;public void setName(String name) {this.name = name;}public void setSex(char sex) {this.sex = sex;}@Overridepublic String toString() {return name+","+sex;}
}
<!--第二种: setter设值注入-->
<bean id="user" class="com.cd4356.demo5.User"><property name="name" value="李四"/><property name="sex" value="男"/>
</bean>
p命名空间注入
  • 目的:简化 xml 的配置
  • 需在<beans>标签内引入 p命名空间 xmlns:p="http://www.springframework.org/schema/p"
  • <bean>标签内通过 p:属性名=“属性值”p:对象属性名-ref=“引用对象的id”来设置注入的属性
public class Teacher {private String name;private String role;public void setName(String name) {this.name = name;}public void setRole(String role) {this.role = role;}@Overridepublic String toString() {return "Teacher{" +"name='" + name + '\'' +", role='" + role + '\'' +'}';}
}
public class Student {private String name;private String role;private Teacher teacher;public void setName(String name) {this.name = name;}public void setRole(String role) {this.role = role;}public void setTeacher(Teacher teacher) {this.teacher = teacher;}@Overridepublic String toString() {return "Student{" +"name='" + name + '\'' +", role='" + role + '\'' +", teacher=" + teacher +'}';}
}
<!--第三种: p命名空间注入-->
<bean id="teacher" class="com.cd4356.demo5.Teacher" p:name="李钦" p:role="教师"/>
<bean id="student" class="com.cd4356.demo5.Student" p:name="赖红" p:role="学生" p:teacher-ref="teacher"/><!--注意: 这种方式要事先在`<beans>`标签内引入`xmlns:p="http://www.springframework.org/schema/p"`-->
SpEL注入
  • SpEL(Spring Expression Language)Spring表达式语言,对依赖注入进行简化

  • SpEL语法:#{表达式}

    • #{‘张三’} :字符串
    • #{99.9} :整形/浮点型
    • #{beanId} : 引用其它bean
    • #{beanId.bean方法} :通过beanId使用该bean中的方法
public class Category {private String name;public void setName(String name) {this.name = name;}@Overridepublic String toString() {return "Category{" +"name='" + name + '\'' +'}';}
}
public class Product {private String name;private Double price;private Category category;public void setName(String name) {this.name = name;}public void setPrice(Double price) {this.price = price;}public void setCategory(Category category) {this.category = category;}@Overridepublic String toString() {return "Product{" +"name='" + name + '\'' +", price=" + price +", category=" + category +'}';}public Double calculatePrice(){Double price=Math.random()*99.8;return price;}
}
<!--第四种: SpEL注入-->
<bean id="category" class="com.cd4356.demo7.Category"><property name="name" value="#{'水果'}"/>
</bean>
<bean id="product" class="com.cd4356.demo7.Product"><property name="name" value="#{'雪梨'}"/><property name="price" value="#{product.calculatePrice()}"/><property name="category" value="#{category}"/>
</bean>
复杂类型的属性注入(xml)
  • 简单类型(8种数据类型+String

  • 对象类型

  • List、Map、Set 、Array 和 Properties

简单类型
  • 由于前面的案例使用的都是,所以这里就不在做介绍了
对象类型
  • 构造器注入 和 setter设值注入方式   注入对象类型属性是通过ref引入其它bean的id来实现的
  • p命名空间注入  通过p:对象属性名-ref=“引用对象的id”来设值注入的属性
package com.cd4356.demo5;public class Teacher {private String name;private char sex;public void setName(String name) {this.name = name;}public void setSex(char sex) {this.sex = sex;}@Overridepublic String toString() {return name+","+sex;}
}
package com.cd4356.demo5;public class Student {private String name;private char sex;private Teacher teacher;public void setName(String name) {this.name = name;}public void setSex(char sex) {this.sex = sex;}public void setTeacher(Teacher teacher) {this.teacher = teacher;}@Overridepublic String toString() {return name+","+sex+","+teacher;}
}
<!--第二种: setter设值注入-->
<bean id="student" class="com.cd4356.demo5.Student"><!--注入简单类型属性--><property name="name" value="赖红"/><property name="sex" value="女"/><!--注入对象类型属性--><property name="teacher" ref="teacher"/>
</bean>
<bean id="teacher" class="com.cd4356.demo5.Teacher"><property name="name" value="李钦"/><property name="teachingCourse" value="android开发"/>
</bean>

注意到了吗,简单类型属性赋值使用 value,而对象类型属性赋值使用 ref 引入其它bean的 id 或 name的进行关联

List、Map、Set 、Array 和 Properties
package com.cd4356.demo6;
import java.util.*;public class AllCollectionType {private List<String> list;private Map<String,String> map;private Set<String> set;private String[] array;private Properties properties;public void setList(List<String> list) {this.list = list;}public void setMap(Map<String, String> map) {this.map = map;}public void setSet(Set<String> set) {this.set = set;}public void setArray(String[] array) {this.array = array;}public void setProperties(Properties properties) {this.properties = properties;}@Overridepublic String toString() {return "AllCollectionType{" +"\n list=" + list +"\n map=" + map +"\n set=" + set +"\n array=" + Arrays.toString(array) +"\n properties=" + properties +"\n}";}
}
<!--注入各种集合数据类型List、Map、Set、Array、Properties等...-->
<bean id="allCollectionType" class="com.cd4356.demo6.AllCollectionType"><!--为List属性赋值--><property name="list"><list><value>足球</value><value>蓝球</value><value>排球</value></list></property><!--为Map属性赋值--><property name="map"><map><entry key="man" value="男人"/><entry key="women" value="女人"/><entry key="Ladyboy" value="人妖"/></map></property><!--为Set属性赋值--><property name="set"><set><value>小学生</value><value>初中生</value><value>高中生</value></set></property><!--为Array属性赋值--><property name="array"><array><value>黑种人</value><value>黄种人</value><value>白种人</value></array></property><!--为Properties属性赋值--><property name="properties"><props><prop key="apple">苹果</prop><prop key="pear">雪梨</prop><prop key="orange">橘子</prop></props></property>
</bean>

基于注解方式的 bean 管理

注解配置实例化bean

基于注释的配置提供了XML设置的替代方案,该配置依赖于字节码元数据来连接组件而不是角括号声明。即开发人员不是使用XML来描述bean连接,而是通过在相关的类、方法或字段声明上使用注释将配置移动到组件类本身

  • 注解配置需在spring配置文件中引入context命名空间

OK,下面通过一个案例来尝试一下

package com.cd4356.demo1;
import org.springframework.stereotype.Component;@Component("userService") //这里使用@Service更合适
public class UserService {public String introduce(String name){return "你好,我叫"+name;}
}
<!--配置全局扫描-->
<context:component-scan base-package="com.cd4356"/>

上述配置与以下Spring XML等效:

package com.cd4356.demo1;public class UserService {public String introduce(String name){return "你好,我叫"+name;}
}
<bean id="userService" class="com.cd4356.demo1.UserService"/>

注意到了吗?在上面使用注解的示例中的两个不同之处:

  • 在类的声明上使用了@Component注解
  • 在xml配置文件中声明了包扫描驱动 <context:component-scan base-package=""/>

@Component

  • 如果不指定id,则会默认生成一个类名首字母小写的id

  • 把普通pojo类实例化到spring容器中,相当于配置文件中的<bean id="" class=""/>

  • @component 泛指各组件,就是说当我们的类不属于各种归类(@Controller、@Service、@Repository)的时候,我们就可以使用@Component来标注该类

虽然controller、service、dao类型的类也是可以使用@Component来标注的,但不建议,针对不同类型的类,我们有与之对应注解匹配

  • @Controller 标注控制层的类,即Controller层

  • @Service 标注服务层的类,即Service层

  • @Repository 标注数据访问层的类,即Dao层

我们仅是在类上使用注解是无法将该类实例化的,还需在xml配置文件中,声明了包扫描驱动<context:component-scan />

<context:component-scan />

  • 作用:在Spring容器启动时会启动注解驱动去 扫描base-package 指定包下的bean对象并将创建它们的实例,这样我们就无需一个个地进行bean配置声明了,极大简化了编程代码

注解实现属性注入

  • 普通类型属性注入

  • 对象类型属性注入

普通类型属性注入
  • 普通类型属性注入,通过@Value注解来实现
  • 类中如果有setter方法,那么注解既可以加到属性上方,也可以加到setter方法上方(不能加到getter方法上)
package com.cd4356.demo1;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;@Service
public class UserService {@Value("李钦")private String name;public String introduce(){return "你好,我叫"+name;}
}

注意,配置注解扫描,注解再能生效

<!--配置全局扫描-->
<context:component-scan base-package="com.cd4356"/>
@Test /*使用@Test注解后,可以不用在main方法中进行测试,提高测试效率*/
public void demo1(){// 创建spring工厂ApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring.xml");// 通过工厂获得类对象UserService userService= (UserService) applicationContext.getBean("userService");System.out.println(userService.introduce());
}
对象类型属性注入
  • 按类型自动装配 @Autowired
package com.cd4356.demo1;import org.springframework.stereotype.Repository;@Repository
public class UserDao {public void print(){System.out.println("打印Dao的方法");}
}
package com.cd4356.demo1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service //声明这是一个service的bean
public class UserService {@Autowired //自动装配UserDaoprivate UserDao userDao;public void test(){userDao.print();}
}
  • 按bean名称自动装配

    • @Autowired + @Qualifier

    • @Resource(@Resource = @Autowired + @Qualifier)

使用@Autowired + @Qualifier进行装配
  • 使用@Qualifier指定注入bean的名称后,注解bean必须指定相同的名称
package com.cd4356.demo1;
import org.springframework.stereotype.Repository;@Repository("userDao") //声明这是一个dao的bean
public class UserDao {public void print(){System.out.println("打印Dao的方法");}
}
package com.cd4356.demo1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;@Service //声明这是一个service的bean
public class UserService {@Autowired //自动装配UserDao@Qualifier("userDao") //指定注入bean的名称private UserDao userDao;public void test(){userDao.print();}
}
使用@Resource进行装配
  • @Resource 注解需通过name属性指定注解bean的名称
package com.cd4356.demo1;
import org.springframework.stereotype.Repository;@Repository("userDao") //声明这是一个dao的bean
public class UserDao {public void print(){System.out.println("打印Dao的方法");}
}
package com.cd4356.demo1;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;@Service //声明这是一个service的bean
public class UserService {@Resource(name = "userDao") // @Resource = @Autowired + @Qualifierprivate UserDao userDao;public void test(){userDao.print();}
}
其它类型注解
  • bean生命周期的注解

  • bean作用范围的注解

  • . . .

bean生命周期的注解

Spring 在初始化bean 或者 销毁bean时,有时需要做一些处理工作,因此Spring可以在创建或拆卸bean的时候调用bean的两个生命周期方法

  • 初始化bean方法 @PostConstruct

  • 销毁bean方法 @PreDestroy

package com.cd4356.demo1;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;@Component // 声明这是一个bean
public class Bean {@PostConstruct // 初始化bean的方法public void init(){System.out.println("init bean. . .");}public void introduce(){System.out.println("我是 . . .");}@PreDestroy // 销毁bean的方法public void destory(){System.out.println("destory bean. . .");}
}
@Test /*使用@Test注解后,可以不用在main方法中进行测试,提高测试效率*/
public void demo1(){// 创建spring工厂,加载spring配置文件,创建bean实例ApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring.xml");// 通过工厂获得类对象Bean bean= (Bean) applicationContext.getBean("bean");bean.introduce();// 关闭工厂(接口中没有关闭的方法,实现类中才有,需强转类型), 销毁bean((ClassPathXmlApplicationContext) applicationContext).close();
}
bean作用范围的注解
  • 使用注解配置和使用配置一样,默认的作用范围都是 singleton (单例模式,对象地址一样)

  • @Scope注解用于指定bean的作用范围

    • singleton单例 (bean地址一样
    • prototype多例(bean地址不一样

singleton(默认)

package com.cd4356.demo1;
import org.springframework.stereotype.Component;@Component // 声明这是一个bean
public class Bean {}
@Test /*使用@Test注解后,可以不用在main方法中进行测试,提高测试效率*/
public void demo1(){// 创建spring工厂,加载spring配置文件,创建bean实例ApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring.xml");// 通过工厂获得类对象Bean bean1= (Bean) applicationContext.getBean("bean");Bean bean2= (Bean) applicationContext.getBean("bean");System.out.println(bean1==bean2);
}

打印输出: true

prototype

package com.cd4356.demo1;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;@Component // 声明这是一个bean
@Scope("prototype") // bean的作用范围为prototype多例,bean地址不一样
public class Bean {}
@Test /*使用@Test注解后,可以不用在main方法中进行测试,提高测试效率*/
public void demo1(){// 创建spring工厂,加载spring配置文件,创建bean实例ApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring.xml");// 通过工厂获得类对象Bean bean1= (Bean) applicationContext.getBean("bean");Bean bean2= (Bean) applicationContext.getBean("bean");System.out.println(bean1==bean2);
}

打印输出: false

在学了基于xml和基于注解的bean管理后,就会引发一个问题:

注释是否比配置Spring的XML更好?

答案:

  • 每种方法都有其优点和缺点,通常由开发人员决定哪种策略更适合他们。

  • XML配置结构清晰,易于阅读,但属性注入方面不够方便,在进行大量属性注入时,配置就会显得复杂

  • 注解配置开发便捷,属性注入方便,但配置变得分散且难以控制

所以更多时候我们会将XML和注解进行整合开发 ,XML配置bean,注解完成属性注入(注解注入在XML注入之前执行,因此XML注入属性将覆盖注解注入的属性)

XML和注解整合开发

  • XML配置管理bean

  • 注解配置属性注入

package com.cd4356.demo1;public class Student {public void stu(){System.out.println("我是一名学生. . .");}
}
package com.cd4356.demo1;public class School {public void sch(){System.out.println("中心小学");}
}
package com.cd4356.demo1;
import javax.annotation.Resource;public class Person {@Resource(name = "student")private Student student;@Resource(name = "school")private School school;public void introduce(){student.stu();school.sch();}
}

如果无需扫描@Controller、@Service、@Repository,@Component等声明bean的注解时,可以使用<context:annotation-config/>注册驱动,使@Autowired、@Resource、@Value等属性注入类型注解 和 bean作用范围注解@Scope 以及 调用bean的两个生命周期方法的注解@PostConstruct、@PreDestroy等. . . 生效,但<context:annotation-config/>不能扫描@Controller、@Service、@Repository,@Component等类上的注解,扫描@Controller、@Service、@Repository,@Component等类上的注解需配置包扫描注册驱动<context:component-scan />,并且配置<context:component-scan />后就无需再配置<context:annotation-config/>了,因为<context:component-scan />已包含了<context:annotation-config/>的功能

<!--注册驱动,使@Autowired、@Resource、@Value等属性注入类型注解生效-->
<context:annotation-config/><bean id="student" class="com.cd4356.demo1.Student"/>
<bean id="school" class="com.cd4356.demo1.School"/>
<bean id="person" class="com.cd4356.demo1.Person"/>
@Test /*使用@Test注解后,可以不用在main方法中进行测试,提高测试效率*/
public void demo1(){// 创建spring工厂,加载spring配置文件,创建bean实例ApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring.xml");// 通过工厂获得类对象Person person= (Person) applicationContext.getBean("person");person.introduce();
}

基于XML和注解的Spring Bean管理相关推荐

  1. Spring——Bean管理-xml方式进行属性注入

    目录 一.xml方式创建对象 二.xml方式注入属性 第①种方式注入:set方法注入 第②种方式注入:有参构造函数注入 constructor-arg:通过构造函数注入 用name标签属性: 不按照顺 ...

  2. 【一步一步学习spring】spring bean管理(上)

    1. spring 工厂类 我们前边的demo中用到的spring 工厂类是ClassPathXmlApplicationContext,从上图可以看到他还有一个兄弟类FileSystemApplic ...

  3. java学习day40(Spring)spring中的aop和基于XML以及注解的AOP配置

    第1章 AOP 的相关概念[理解] 1.1AOP 概述 1.1.1 什么是 AOP AOP :全称是 Aspect Oriented Programming 即:面向切面编程. 简单的说它就是把我们程 ...

  4. 使用 Java 配置进行 Spring bean 管理--转

    概述 众所周知,Spring 框架是控制反转 (IOC) 或依赖性注入 (DI) 模式的推动因素,而这种推动是通过基于容器的配置实现的.过去,Spring 允许开发人员使用基于 XML 的配置,通过利 ...

  5. 使用 Java 配置进行 Spring bean 管理

     https://www.ibm.com/developerworks/cn/webservices/ws-springjava/ 概述 众所周知,Spring 框架是控制反转 (IOC) 或依赖 ...

  6. 基于XML及注解配置方式实现AOP及aspectJ表达式

    aspectJ表达式结构 切入点表达式 execution (* com.sample.service.impl...(..)) 1.execution(): 表达式主体. 2.第一个号:表示返回类型 ...

  7. Spring框架学习笔记07:基于XML配置方式使用Spring MVC

    文章目录 一.Spring MVC概述 1.MVC架构 2.Spring MVC 3.使用Spring MVC的两种方式 二.基于XML配置与注解的方式使用Spring MVC (一)创建Spring ...

  8. Spring - Bean注解配置光速入门

    Bean注解配置光速入门 步骤一: 创建 web 项目,引入 Spring 的开发包 在 Spring 的注解的 AOP 中需要引入 spring-aop 的 jar 包 步骤二: 引入相关配置文件 ...

  9. Spring 事务管理

    http://www.redsaga.com/spring_ref/2.0/html/transaction.html#transaction-declarative 9.1. 简介 Spring框架 ...

最新文章

  1. 【数学知识】三种方法求 [1,n] 中所有数欧拉函数(线性筛欧拉函数优化至 O(n) )
  2. PHP 在 Nginx 下主动断开连接 Connection Close 与 ignore_user_abort 后台运行
  3. 嵌入式jetty的HTTP实现
  4. 初识Hibernate之关联映射(一)
  5. springcloud 组件_深入理解 Spring Cloud 核心组件与底层原理
  6. flink报错:Error: Static methods in interface require -target:jvm-1.8 已解决
  7. Kubernetes 为 Namespace 配置CPU和内存配额
  8. 微软推出 Power Platform 漏洞奖励计划
  9. android 行居中,android自己定义换行居中CenterTextView
  10. Log4j2的常用配置
  11. COLING 2022提交要求与ACL模板要求记录
  12. 【TSP问题】基于禁忌搜索算法求解旅行商问题Matlab源码
  13. 汇编语言转c语言的软件,Arm汇编转换器下载
  14. 阿里大鱼短信接口PHP版,精简版阿里大鱼短信SMS发送接口PHP实例
  15. 理解算法中的时间复杂度,O(1),O(n),O(log2n),O(n^2)
  16. 解决cmd中文输入法看不到待选文字
  17. pytorch 中 利用自定义函数 get_mask_from_lengths(lengths, max_len)获取每个batch的mask
  18. nss版本 linux,在CentOS系统中VSCode无法启动原来是NSS版本过低
  19. 直播+时尚跨界掀起新玩法,传统时装行业变革在即
  20. 2021年塔式起重机司机考试题及塔式起重机司机免费试题

热门文章

  1. 第一篇:对Adaboost和GBDT的学习
  2. MySQL使用触发器实现check约束功能
  3. 面试官:说说你知道多少种线程池拒绝策略
  4. 大白话5分钟带你走进人工智能-第31节集成学习之最通俗理解GBDT原理和过程
  5. 转载:GBDT算法梳理
  6. (python)查看糗事百科文字 点赞 作者 等级 评论
  7. Linux下如何查看哪些进程占用的CPU内存资源最多
  8. 可以获取get post url 传递参数的统一方法
  9. IOS多线程任务(综述篇)
  10. Html和CSS在浏览器中常见的兼容性问题处理