POJO 意为 plain (无装饰的,朴素的) Old java Object
spring所需依赖:
<!-- Spring的核心组件 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.2.18.RELEASE</version>
</dependency>
<!-- SpringIoC(依赖注入)的基础实现 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.2.18.RELEASE</version>
</dependency>
<!--Spring提供在基础IoC功能上的扩展服务,此外还提供许多企业级服务的支持,如邮件服务、任务调度、JNDI定位、EJB集成、远程访问、缓存以及各种视图层框架的封装等 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.18.RELEASE</version>
</dependency>
Spring框架实现控制反转(IoC)的原理, IoC也称为依赖注入(DI);
ApplicationContext是BeanFactory的子接口
【applicationcontext】接口表示Spring IoC容器,并负责实例化、配置和组装bean。 容器通过读取配置元数据获得关于要实例化、配置和组装哪些对象的指令。 配置元数据以XML、Java注解或Java代码表示。 它允许您表达组成应用程序的对象以及这些对象之间丰富的相互依赖关系。
基于xml的配置元数据的基本结构:
<?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
https://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="..." class="...">
<!-- collaborators and configuration for this bean go here -->
</bean>
<bean id="..." class="...">
<!-- collaborators and configuration for this bean go here -->
</bean>
<!-- more bean definitions go here -->
</beans>
-
' id '属性是标识单个beanDifination的字符串。
-
' class '属性定义bean的类型,并使用完全限定的类名
-
容器中的对象都是单例的,可以避免资源的浪费。
bean的别名:
<bean id="UserDao" name="dao,dao2,dao3" class="com.pl.UserDao">
<!-- collaborators and configuration for this bean go here -->
</bean>
alias可以给bean再起别名:
alias= dao4