随笔分类 -  Spring4

Spring4
摘要:SpringIOC综合 SpringAOP综合 阅读全文
posted @ 2020-04-19 15:20 linglongfang 阅读(100) 评论(0) 推荐(0)
摘要:1.SpringAOP相关术语 2.SpringAOP-xml配置AOP-xml+注解配置AOP 3.SpringAOP-xml配置AOP-纯xml配置AOP 阅读全文
posted @ 2020-04-19 15:16 linglongfang 阅读(91) 评论(0) 推荐(0)
摘要:AOP相关术语 1、目标对象target指的是需要被增强的对象,由于spring aop是通过代理模式实现,从而这个对象永远是被代理对象。2、连接点(join point)所谓连接点是指那些被拦截到的点,在spring中这些点指的是方法,因为spring只支持方法类型的连接点(目标对象中所有的方法) 阅读全文
posted @ 2020-04-19 13:20 linglongfang 阅读(416) 评论(0) 推荐(0)
摘要:实体类如下 Calculation是我们用的类,PointCut是我们要实现通知的切面类 Calculation类如下 package com.llf.aop; import org.springframework.stereotype.Component; /** * @author linglo 阅读全文
posted @ 2020-04-19 13:18 linglongfang 阅读(229) 评论(0) 推荐(0)
摘要:实体类如下 Calculation是我们用的类,PointCut是我们要实现通知的切面类 Calculation类如下 package com.llf.aop.xml; /** * @author linglongfang */ public class Calculation { public i 阅读全文
posted @ 2020-04-19 13:10 linglongfang 阅读(299) 评论(0) 推荐(0)
摘要:静态代码模式的基本介绍 静态代理在使用时,需要定义接口或者父类,被代理对象(即目标对象)与代理对象一起实现相同的接口或者是继承相同父类 特别提醒:代理对象与目标对象要实现相同的接口,然后通过调用相同的方法来调用目标对象的方法。 代码示例 共同的接口 package com.llf.proxy.sta 阅读全文
posted @ 2020-04-18 22:31 linglongfang 阅读(122) 评论(0) 推荐(0)
摘要:偷个懒 spring泛型依赖注入 阅读全文
posted @ 2020-04-18 19:50 linglongfang 阅读(104) 评论(0) 推荐(0)
摘要:在Spring注解配置Bean中,如果bean的属性也是一个Bean,那么我们可能就需要用到自动装配了 一般需要在属性上加入 @Autowire @Resource @Inject 3个注解中的任何一个都可以 可以参考: annotation之@Autowired、@Inject、@Resource 阅读全文
posted @ 2020-04-18 19:26 linglongfang 阅读(190) 评论(0) 推荐(0)
摘要:SpringIOC容器要使用注解配置Bean,那么必须要有aop的jar包 用于表示Bean的注解主要有一下四种 @Component @Service @Controller @Repository 光光加上注解是没有用的,还需要在xml文件中对这些注解进行扫描,xml扫描配置如下 这里的base 阅读全文
posted @ 2020-04-18 18:53 linglongfang 阅读(734) 评论(0) 推荐(0)
摘要:继承FactoryBean接口 package com.llf.bean.factorybean; import com.llf.bean.Car; import org.springframework.beans.factory.FactoryBean; /** * @author linglon 阅读全文
posted @ 2020-04-18 18:28 linglongfang 阅读(189) 评论(0) 推荐(0)
摘要:一、实验使用实体类 1.静态工厂配置Bean 静态工厂类 StaticFactory package com.llf.bean.factory; import com.llf.bean.Car; import java.util.HashMap; import java.util.Map; /** 阅读全文
posted @ 2020-04-18 18:13 linglongfang 阅读(282) 评论(0) 推荐(0)
摘要:一、实验使用实体类 Car中有init方法和destory方法 Bean可以指定自己的初始化方法和销毁方法,在xml的bean标签中显示如下 (这里的方法名可以可以随便定义,不一定要是init和destroy,标签的属性名对就行了) <bean id="car" class="com.llf.bea 阅读全文
posted @ 2020-04-18 17:10 linglongfang 阅读(230) 评论(0) 推荐(0)
摘要:偷个懒,引用下别人的 SpEL表达式总结 阅读全文
posted @ 2020-04-18 15:55 linglongfang 阅读(151) 评论(0) 推荐(0)
摘要:引入外部资源配置文件 通常我们使用数据库连接池等等第三方jar包,会有一堆配置,如数据库基本信息等,如果全写在一个,修改起来很是麻烦,那么我们可以放在一个properties的资源文件中 如db.properties user=root password=123456 jdbcUrl=jdbc:my 阅读全文
posted @ 2020-04-18 15:40 linglongfang 阅读(389) 评论(0) 推荐(0)
摘要:纯粹的SpringIOC容器中,bean的作用域有2中,用bean标签中的scope来标注,分别是singleton和prototype singleton表示SpringIOC容器在初始化的时候,会创建此bean,每次请求的时候,返回的都是这个bean的实例(单例) prototype表示Spri 阅读全文
posted @ 2020-04-18 15:11 linglongfang 阅读(190) 评论(0) 推荐(0)
摘要:一、实验使用实体类 这2个类,并没有实际的父子关系,只是属性值一样 1.xml中,将Father类作为Son类的Parent 此时son这个bean的name是:llf,age是:22 。属性值完全继承于father这个bean,但是2个bean没有实际的继承关系,father只是作为一个模板的作用 阅读全文
posted @ 2020-04-17 22:06 linglongfang 阅读(466) 评论(0) 推荐(0)
摘要:前面我们都是当bean中要引用另一个bean的时候,我们都是采用了ref去指定确切的bean的id 那么,Spring为我们提供了自动装配的功能,只需要在bean上添加一个属性即可 autowire属性,这个属性有2个值:byName和byType 当值为byName的时候,bean中属性(引用类型 阅读全文
posted @ 2020-04-17 18:23 linglongfang 阅读(184) 评论(0) 推荐(0)
摘要:一、实验使用实体类 使用p空间去简化 <bean id="car" class="com.llf.bean.Car" p:brand="宝马" p:price="100000.0" p:speed="200" ></bean> 同样也可以使用ref <bean id="car" class="com 阅读全文
posted @ 2020-04-17 17:15 linglongfang 阅读(158) 评论(0) 推荐(0)
摘要:一、实验使用实体类 RichMan类中有一个属性的类型是List<Car>类型 GreatMan类中有一个属性的类型是Map<String,Car>类型 这里不再使用Car类的有参构造方法,因为Car类这里只是为了new对象被RichMan和GreatMan所注入 1.将List注入,如果是引用类型 阅读全文
posted @ 2020-04-17 16:54 linglongfang 阅读(368) 评论(0) 推荐(0)
摘要:一、实验使用实体类 Person类中有一个属性的类型是Car类型 这里不再提供Car类的有参构造方法,因为Car类这里只是为了new对象被Person所注入 Person提供有参构造方法 //无参构造 public Person() { } //有参构造 public Person(String n 阅读全文
posted @ 2020-04-17 16:08 linglongfang 阅读(312) 评论(0) 推荐(0)