![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
spring学习笔记
JinF~
这个作者很懒,什么都没留下…
展开
-
Bean的生命周期小结
实例化BeanFactoryPostProcessor,执行BeanFactoryPostProcessor.postProcessBeanFactory()作用是:在bean实例创建前,可以获取定义bean的元数据,从而覆盖或者添加bean的属性在bean对象的构造函数调用前调用InstantiationAwareBeanPostProcess.postProcessBeforeInstantiation()...原创 2020-10-15 22:05:33 · 82 阅读 · 0 评论 -
@Autowired详解与注意事项
@Autowired注意事项:如果容器中存在一个bean,这个bean的类型与id与被标注@Autowired的属性或者方法参数的类型与名称相同,那么此时的@Autowired相当于@Autowired@Qualifier("属性名")例如存在一个接口TestInterface,有两个实现类分别是TestClass1和TestClass2都在spring容器中,此时有一个SomeClass类需要注入一个TestInterface属性,代码如下:@Component@Slf4jpubl原创 2020-10-13 21:39:14 · 8121 阅读 · 0 评论 -
配置Bean的初始化与销毁方法 与init前后的处理
普通Java程序需要使用((AbstractApplicationContext)context).close();显式指定关闭spring容器,destory方法才会运行普通Bean对象通过init-method和destroy-method指定初始化与销毁方法public class Student implements Serializable { //...... public void init(){ log.debug("init..."); }原创 2020-10-13 17:12:31 · 282 阅读 · 0 评论 -
spring 整合 mybatis 三种方法
第一种:需要另外写dao层继承SqlSessionDaoSupport抽象类,使用super.getSqlSession()获取SqlSession对象后再使用mapper接口,service层使用的是dao层缺点是需要另外实现dao层public class MyBatisCardDao extends SqlSessionDaoSupport{ public Card getCardByStudentId(String id) { SqlSession sqlSes.原创 2020-10-11 17:26:44 · 116 阅读 · 0 评论 -
spring整合普通Servlet web项目 在web.xml文件中配置spring容器启动
web.xml文件中配置如下:可以通过<param-value>classpath:application.xml</param-value>显式指定spring配置文件的位置;如果不指定的话,spring的配置文件名必须是applicationContext.xml,且必须放在WEB-INF下<param-value>中可以配置多个配置文件,每个配置文件路径使用,分开,也可以使用*通配符对相同前缀或者相同后缀的xml配置文件进行加载<!DOCTYPE原创 2020-10-11 13:32:58 · 262 阅读 · 1 评论 -
spring 基于注解实现aop详细实现代码
需要的包:没有aspectjrt的话会找不到@AspectJ注解除了以上两个之外,只需要导入 <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependen原创 2020-10-10 17:58:38 · 208 阅读 · 0 评论 -
spring 基于xml的AOP 2种方式
第一种通过实现接口实现通知类型需要实现的接口前置通知org.springframework.aop.MethodBeforeAdvice后置通知org.springframework.aop.AfterReturningAdvice异常通知org.springframework.aop.ThrowsAdvice环绕通知org.aopalliance.intercept.MethodInterceptor前置通知的接口实现@Slf4jpubl.原创 2020-10-10 17:15:34 · 187 阅读 · 0 评论 -
spring基于xml的自动装配
官网说明表格:mode说明no(默认)无自动装配。 Bean引用必须由ref元素定义。对于大型部署,建议不要更改默认设置,因为明确指定协作者可以提供更好的控制和清晰度。在某种程度上,它记录了系统的结构。byName按属性名称自动装配。 Spring寻找与需要自动装配的属性同名的bean。例如,如果一个bean定义被设置为按名称自动装配,并且包含一个master属性(即,它具有setMaster(…)方法),那么Spring将查找一个名为master的bean定义并使用它来设置翻译 2020-10-09 15:53:31 · 357 阅读 · 0 评论 -
spring 特殊值的依赖注入
注入空(null)<bean class="ExampleBean"> <property name="email"> <null/> </property></bean>注入 > < 等特殊符号<bean class="ExampleBean"> <property name="someString" value="<"></p.原创 2020-10-09 15:45:40 · 79 阅读 · 0 评论 -
spring 使用静态工厂方法和factoryBean进行依赖注入
类的定义示例如下:public class ExampleBean { // a private constructor private ExampleBean(...) { ... } // a static factory method; the arguments to this method can be // considered the dependencies of the bean that is returned, //原创 2020-10-09 13:55:49 · 695 阅读 · 0 评论 -
spring 基于构造函数的依赖注入
第一种情况:注入的是引用类型不显式的指定构造函数参数索引或类型,此时构造函数注入的顺序必须可以任意,但是ThingTwo和ThingThree不应该存在继承关系public class ThingOne { public ThingOne(ThingTwo thingTwo, ThingThree thingThree) { // ... }}<beans> <bean id="beanOne" class="x.y.ThingOne.原创 2020-10-09 11:03:36 · 315 阅读 · 0 评论 -
spring 集合 数组 Map类型的依赖注入方式
<bean id="moreComplexObject" class="example.ComplexObject"> <!-- results in a setAdminEmails(java.util.Properties) call --> <property name="adminEmails"> <props> <prop key="administrator">administra原创 2020-10-09 11:02:07 · 380 阅读 · 0 评论