Spring入门配置和DL依赖注入实现图解

网友投稿 546 2023-03-23

Spring入门配置和DL依赖注入实现图解

Spring入门配置和DL依赖注入实现图解

1、Spring入门配置

1.1、起别名

给项目起别名

1.2、import

导入其他xml

1.3、Bean的配置最重要的,又很多配置,我们先学一点

2、依赖注入(DL)

很重要

2.1、set注入

三种方式:

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://springframework.org/schema/beans

https://springframework.org/schema/beans/spring-beans.xsd">

情商高

智慧

沉稳

有钱

赚钱

情商

心理学

经济学

哲学

英语

数学

计算

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://springframework.org/schema/beans

https://springframework.org/schema/beans/spring-beans.xsd">

情商高

智慧

沉稳

有钱

赚钱

情商

心理学

经济学

哲学

英语

数学

计算机

记住这些类型的注入就行了

2.2、构造器注入

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://springframework.org/schema/beans

https://springframework.org/schema/beans/spring-beans.xsd">

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://springframework.org/schema/beans

https://springframework.org/schema/beans/spring-beans.xsd">

注意:我们一般选用 key value注入,见名知意

2.3、拓展注入

为了简化我们可以引入p/c命名空间

使用方式:

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:p="http://springframework.org/schema/p"

xmlns:c="http://springframework.org/schema/chttp://"

xsi:schemaLocation="http://springframework.org/schema/beans

https://springframework.org/schema/beans/spring-beans.xsd">

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xmlns:p="http://springframework.org/schema/p"

xmlns:c="http://springframework.org/schema/chttp://"

xsi:schemaLocation="http://springframework.org/schema/beans

https://springframework.org/schema/beans/spring-beans.xsd">

注意点:

使用前要导入:

xmlns:p="http://springframework.org/schema/p"

xmlns:c="http://springframework.org/schema/c"

类比:

p相当于标签:properties 其实就是set注入,不过可以简化简单的操作

c详单与 :constructor:就是用来给有参构造器初始化的

2.4、bean标签作用域

bean是什么?就是一个对象,也就是类的实例

我们可以给他设置单例模式等等

单例模式

原型模式

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:电脑微信怎么打开小程序页面(电脑微信端怎么打开小程序)
下一篇:详解MyBatis配置typeAliases的方法
相关文章

 发表评论

暂时没有评论,来抢沙发吧~