
spring基础
cc_xxo
这个作者很懒,什么都没留下…
展开
-
Spring基础——AOP
AOP术语 1、连接点:类里面可以被增强的方法 2、切入点:实际被增强的方法 3、通知(增强):实际增强的逻辑部分。通知类型有多种:前置通知@Before、后置通知@AfterReturning、环绕通知@Around、异常通知@AfterThrowing、最终通知@After 4、切面:是动作,吧通知应用到接入点过程 1、Spring 框架一般都是基于 AspectJ 实现 AOP 操作 (1)AspectJ 不是 Spring 组成部分,独立 AOP 框架,一般把 AspectJ 和 Spirng原创 2022-03-19 22:58:20 · 245 阅读 · 0 评论 -
spring基础——注解注入
Spring 针对 Bean 管理中创建对象提供注解 (1)@Component (2)@Service (3)@Controller (4)@Repository 配置文件 1、注解注入要先引入context名称空间 xmlns:context=“http://www.springframework.org/schema/context” http://www.springframework.org/schema/context http://www.springframework.org/schema/原创 2022-03-19 19:35:11 · 2675 阅读 · 0 评论 -
spring基础——外部引入属性文件创建bean
1、引入context名称空间 xmlns:context=“http://www.springframework.org/schema/context” http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 2、创建属性配置文件 .properties 以 Druid 为例 prop.driverClassName=com.mysql.jd原创 2022-03-19 15:33:07 · 978 阅读 · 0 评论 -
spring基础——<bean>scope属性
通过对scope属性的设置可实现单例或多例,默认不设置为单例 singleton 单例(默认值) prototype 多例 例如 <bean id="user" class="spring.User" scope="prototype"></bean> 判断是多例还是单例 ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml"); User user1 = beanFactory.getB原创 2022-03-19 15:23:50 · 609 阅读 · 0 评论 -
Spring——bean生命周期
(1)通过构造器创建 bean (2)为 bean 的属性设置值 (3)调用 bean 的初始化的方法(需要进行配置初始化方法,通过init-method指定初始化方法) (4)使用bean对象 (5)bean销毁(需要进行配置销毁的方法,通过destroy-method指定销毁方法) 例如 public class Orders { private String oname; public Orders() { System.out.println("第一步,执行无参构造创原创 2022-03-19 15:23:33 · 138 阅读 · 0 评论 -
spring——autowire自动注入
通过指定bean标签上的autowire属性可对bean对象进行自动注入 autowire = byName 根据名称注入 autowire = byType 根据类型注入 当有多个bean与属性对应时会出错 <bean id="dept" class="spring5.autowire.Dept"></bean> <bean id="emp1" class="spring5.autowire.Emp" autowire="byName"></bean> &l原创 2022-03-19 15:22:59 · 383 阅读 · 0 评论 -
spring基础——普通bean xml注入
一、基本类型注入 1、set注入,前提是类中声明了属性的set方法 使用\ 2、有参构造器注入,前提是类中声明了有参构造器 使用<constructor-arg name=“参数名” value=“参数值”> 3、注入含特殊符号值,使用<![CDATA[<<南京>>]]> 实际值为<<南京>> 4、p标签注入,需引入p名称空间 xmlns:p=“http://www.springframework.org/schema/p” <原创 2022-03-19 10:57:13 · 1010 阅读 · 0 评论