SPRING小结

spring概念及其应用:
IOC:
管理对象之间的依赖关系和生命周期。将对象之间的依赖耦合关系抽取成模块,由IOC容器管理,提高程序的模块性和灵活性。
org.springframework.beans.factory.BeanFactory接口定义了对象管理的基本方法,包括创建对象,检查对象的属性、检查IOC容器是否包含该对象。是不是单例的。
对象之间的依赖关系通常通过XML文件配置好,交给spring的ioc容器管理。基本配置:
定义bean
<bean id="usedao" class="com.demo.dao.UserDAO" />
<bean name="userdao" class="com.demo.dao.UserDAO" />
其他属性:
scope : 定义对象的形态,可选值: singleton / prototype
depends-on:所依赖的对象,必须在本对象初始化之前初始化,其值为其他bean的ID值。
dependency-check:在注入属性后,是否执行对象属性的依赖检查,其值为:none / simple /object / all
autowire: 对象注入的方式,一般用byName / byType 两种方式。
lazy-init:延迟初始化,true 、 false
abstruct:定义是否为抽象类,此类可以不存在。
parent:java的继承概念的体现。用于指定对象的abstruct类

DI注入依赖:
setter方式:
<property name="atrributeName" value="aa" />
<property name="attributeName" ref="beanId" />
<pooperty name="attributeName">
<idref local="" /> //idref 和value 同义,用于将其他bean的id值作为一个字符串注入进来,local只是使id值
<idref bean="" /> //idref 和value 同义,用于将其他bean的id值作为一个字符串注入进来,bean可以使id或name值
<ref local="" /> //不能跨xml文件,只能指定其他bean的id值
<ref bean="" /> //跨xml文件 ,指定其他bean的id或name值
<ref parent="" /> //父容器bean的id或name值
</property>
constructor方式:
<constructor-arg index="0" ref="" /> // 将对应的bean注入到索引为0的构造函数中
<constructor-arg index="1" ref="" /> // 将对应的bean注入到索引为1的构造函数中
<constructor-arg type="java.lang.String" ref="" />// 根据类型匹配注入参数
<constructor-arg type="int" value="1233" /> // 根据类型注入参数
构造函数可以凭借索引和类型区别注入的参数,但spring推荐索引方式,这样可以避免由于类型冲突造成的错误

注入java.util.List / Map / Set 和 数组:
<property name="list" >
<list>
<value>234</value>
<ref bean="otherBean" />
</list>
</property>
<property name="set" >
<set>
<value>234</value>
<ref bean="otherBean" />
</set>
</property>
<property name="array" >
<list>
<value>234</value>
<ref bean="otherBean" />
</list>
</property>
<property name="properties" >
<props>
<prop key="key1" >prop1</prop>
<prop key="key2" >prop2</prop>
</props>
</property>
<property name="map">
<map>
<entry>
<key>key1<key>
<value>value1</value>
</entry>
<entry>
<key>key2</key>
<value>vlaue2</value>
</entry>
</map>
</property>


AOP: 面向切面编程
aspect: 切面模块化的类。此类中包含了 advice 、pointcut
advice: 横切面关注点实现,为before 、 after 、 after returning 、 after throwing 、around等类型
pointcut: advice其作用的范围,通过相关表达式创建
jointpoint: advice起作用的点
weave: 将目标对象和横切面关注点代码组织的过程
introduce: 动态的将方法添加的目标对象里面
proxy: 代理类 ,兄弟代理 JDK Dynamic proxy、 父子代理 cglib
target: 代理模式的目标类

具体采用哪种方式,spring会自动选择,关键点: target是否实现了接口。JDK Dynamic proxy 、cglib
强制待用cglib方式需配置 :<aop:spring-autoproxy target-proxy-class="true"/>

spring支持annotation和配置文件方式挂历切面类:
annocaton:
@Aspect
@Pointcut("execution(* com.demo.manger.*.*(..))")
@Before("allAddMethod()")
@After("allAfterMethod()")
<aop:spring-autoproxy />启用spring对annotation的支持


XML配置方式:
<aop:config>
<aop:aspect id="xmlAspect" ref="" >
<aop:pointcut id="myPointcut" expressing="execution(* add*(..))" />
<aop:advice pointcut-ref="myPointcut" method="beforeAdd()" />
</aop:aspect>
</aop:config>
内容概要:本文介绍了多种开发者工具及其对开发效率的提升作用。首先,介绍了两款集成开发环境(IDE):IntelliJ IDEA 以其智能代码补全、强大的调试工具和项目管理功能适用于Java开发者;VS Code 则凭借轻量级和多种编程语言的插件支持成为前端开发者的常用工具。其次,提到了基于 GPT-4 的智能代码生成工具 Cursor,它通过对话式编程显著提高了开发效率。接着,阐述了版本控制系统 Git 的重要性,包括记录代码修改、分支管理和协作功能。然后,介绍了 Postman 作为 API 全生命周期管理工具,可创建、测试和文档化 API,缩短前后端联调时间。再者,提到 SonarQube 这款代码质量管理工具,能自动扫描代码并检测潜在的质量问题。还介绍了 Docker 容器化工具,通过定义应用的运行环境和依赖,确保环境一致性。最后,提及了线上诊断工具 Arthas 和性能调优工具 JProfiler,分别用于生产环境排障和性能优化。 适合人群:所有希望提高开发效率的程序员,尤其是有一定开发经验的软件工程师和技术团队。 使用场景及目标:①选择合适的 IDE 提升编码速度和代码质量;②利用 AI 编程助手加快开发进程;③通过 Git 实现高效的版本控制和团队协作;④使用 Postman 管理 API 的全生命周期;⑤借助 SonarQube 提高代码质量;⑥采用 Docker 实现环境一致性;⑦运用 Arthas 和 JProfiler 进行线上诊断和性能调优。 阅读建议:根据个人或团队的需求选择适合的工具,深入理解每种工具的功能特点,并在实际开发中不断实践和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值