摘要: 静态代码模式的基本介绍 静态代理在使用时,需要定义接口或者父类,被代理对象(即目标对象)与代理对象一起实现相同的接口或者是继承相同父类 特别提醒:代理对象与目标对象要实现相同的接口,然后通过调用相同的方法来调用目标对象的方法。 代码示例 共同的接口 package com.llf.proxy.sta 阅读全文
posted @ 2020-04-18 22:31 linglongfang 阅读(114) 评论(0) 推荐(0)
摘要: 偷个懒 spring泛型依赖注入 阅读全文
posted @ 2020-04-18 19:50 linglongfang 阅读(100) 评论(0) 推荐(0)
摘要: 在Spring注解配置Bean中,如果bean的属性也是一个Bean,那么我们可能就需要用到自动装配了 一般需要在属性上加入 @Autowire @Resource @Inject 3个注解中的任何一个都可以 可以参考: annotation之@Autowired、@Inject、@Resource 阅读全文
posted @ 2020-04-18 19:26 linglongfang 阅读(179) 评论(0) 推荐(0)
摘要: SpringIOC容器要使用注解配置Bean,那么必须要有aop的jar包 用于表示Bean的注解主要有一下四种 @Component @Service @Controller @Repository 光光加上注解是没有用的,还需要在xml文件中对这些注解进行扫描,xml扫描配置如下 这里的base 阅读全文
posted @ 2020-04-18 18:53 linglongfang 阅读(720) 评论(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 阅读(177) 评论(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 阅读(273) 评论(0) 推荐(0)
摘要: 一、实验使用实体类 Car中有init方法和destory方法 Bean可以指定自己的初始化方法和销毁方法,在xml的bean标签中显示如下 (这里的方法名可以可以随便定义,不一定要是init和destroy,标签的属性名对就行了) <bean id="car" class="com.llf.bea 阅读全文
posted @ 2020-04-18 17:10 linglongfang 阅读(222) 评论(0) 推荐(0)
摘要: 偷个懒,引用下别人的 SpEL表达式总结 阅读全文
posted @ 2020-04-18 15:55 linglongfang 阅读(141) 评论(0) 推荐(0)
摘要: 引入外部资源配置文件 通常我们使用数据库连接池等等第三方jar包,会有一堆配置,如数据库基本信息等,如果全写在一个,修改起来很是麻烦,那么我们可以放在一个properties的资源文件中 如db.properties user=root password=123456 jdbcUrl=jdbc:my 阅读全文
posted @ 2020-04-18 15:40 linglongfang 阅读(373) 评论(0) 推荐(0)
摘要: 纯粹的SpringIOC容器中,bean的作用域有2中,用bean标签中的scope来标注,分别是singleton和prototype singleton表示SpringIOC容器在初始化的时候,会创建此bean,每次请求的时候,返回的都是这个bean的实例(单例) prototype表示Spri 阅读全文
posted @ 2020-04-18 15:11 linglongfang 阅读(180) 评论(0) 推荐(0)