spring配置文件applicationContext.xml约束头的作用

功能依赖约束约束的具体作用
Spring环境spring-context(webmvc可替代)beansSpring总体环境配置
IOC不需要额外依赖context注解时使用,主要用来读取包或者引入外部文件
DI不需要额外依赖不需要额外约束
AOPaspectjweaver、aop(context中包含)AOP用来配置切面和通知,以及使用注解时使用加载aop的注解驱动
事务spring-tx(可用spring-jdbc代替)tx注解时主要用来开启事务管理者
jdbcTemplatespring-jdbc
1.什么是约束

约束,顾名思义——对所考察物体起限制作用的其他物体,称为约束

在实际的Java Spring框架代码中,我们常常会编写 applicationContext.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"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd">
</beans>
2.约束的作用

我们看到在生成的spring 配置上面会有约束头的存在,他的作用就是对配置文件以及代码起到一定的限制作用,有了他们的存在,代码才能够正常运行。其底层代码可以直接打开给到的网址查看,为了让大家节约时间,我附上一张截图。网址是http://www.springframework.org/schema/beans也可以自己打开看一下,但是基础不是超级雄厚的,估计也是看不懂的。

在这里插入图片描述
在这里插入图片描述

3.约束的类型

Spring的约束类型主要有四种:

1》beans: 最基本,最根本

创建spring文件的时候,在生成的约束头中,除了第一行有个声明版本以及字符编码除外,之后就是<beans></beans> 一对标签了,它是整个整个Spring配置中最基础的。也是最根本的约束。

2》context:读取properties配置

这个标签也是除了<beans>之外使用频率最高的标签了,它是在注解时使用,主要用来读取包或者引入外部文件

在这里插入图片描述

这个图片是上面给到的代码,框到的部分就是属于context 约束头的部分。

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


       <!--这里的就是用来读取包引入外部文件的!!!!-->
    <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${jdbc.driver}"/>
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="user" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>

</beans>
3》aop:配置aop
  待更新
4>tx:配置事务通知
  待更新

IOC:控制反转 用来创建对象 并存入核心容器
DI:依赖注入 将核心容器里面的东西赋值给变量
AOP:面向切面编程 使用切面中的通知去增强切入点的功能

参考其他博客点击跳转

整个Spring需要的依赖(spring环境):spring-context 依赖以及beans约束
		使用IOC注解时需要引入context约束,主要用来读取包
		
		使用AOP时需要依赖:切面依赖 aspectjweaver、aop依赖 以及AOP约束
		
		用来配置切面和通知 以及注解时加载aop的注解驱动<aop:aspectj-autoproxy>
		使用事务管理时需要依赖:tx依赖:spring-tx 以及tx约束(由于jdbc依赖包含了tx,
		可以直接使用spring-jdbc,jdbc也需要用来简化原生jdbc)
		主要用来开启事务管理者
		<tx:annotation-driven transaction-manager="transactionManager"/>
		
		使用jdbcTemplate需要的依赖,jdbc依赖,spring-jdbc。对原生的
		JDBC提供了支持,对原始Jdbc API对象的简单封装。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值