国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

Spring5學習之基礎知識總結

瀏覽:3日期:2022-08-13 10:02:03
1.概述

1、Spring 是輕量級的開源的 JavaEE 框架

2、 Spring 可以解決企業應用開發的復雜性

3、Spring 有兩個核心部分:IOC 和 Aop

IOC:控制反轉,把創建對象過程交給 Spring 進行管理Aop:面向切面,不修改源代碼進行功能增強

4、Spring 特點

方便解耦,簡化開發Aop 編程支持方便程序測試方便和其他框架進行整合方便進行事務操作降低 API 開發難度 2.入門Demo

1.jar包引入

<project xmlns='http://maven.apache.org/POM/4.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd'> <modelVersion>4.0.0</modelVersion> <groupId>cn.zj.springDemo</groupId> <artifactId>springDemo</artifactId> <version>0.0.1-SNAPSHOT</version> <description>spring的入門demo</description> <dependencies><dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>5.3.6</version></dependency><dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>5.3.6</version></dependency><dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.3.6</version></dependency> </dependencies></project>

2.bean

package cn.zj.demo.bean;public class User { public void add() {System.out.println('add....'); } }

3.spring的xml配置

<?xml version='1.0' encoding='UTF-8'?><beans xmlns='http://www.springframework.org/schema/beans' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd'> <!--1 配置User對象創建--> <bean class='cn.zj.demo.bean.User'></bean> </beans>

4.測試代碼

package cn.zj.demo.test;import org.junit.jupiter.api.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import cn.zj.demo.bean.User;public class SpringTest { @Test public void testAdd() {// 1 加載 spring 配置文件ApplicationContext context = new ClassPathXmlApplicationContext('bean1.xml');// 2 獲取配置創建的對象User user = context.getBean('user', User.class);System.out.println(user);user.add(); }}

5.輸出

cn.zj.demo.bean.User@24111ef1add....3.源碼

ApplicationContext context = new ClassPathXmlApplicationContext('bean1.xml');public ClassPathXmlApplicationContext( String[] configLocations, boolean refresh, @Nullable ApplicationContext parent) throws BeansException {super(parent);setConfigLocations(configLocations);if (refresh) { refresh();} }

public void refresh() throws BeansException, IllegalStateException {synchronized (this.startupShutdownMonitor) { StartupStep contextRefresh = this.applicationStartup.start('spring.context.refresh'); //容器刷新前的準備,設置上下文狀態,獲取屬性,驗證必要的屬性等 prepareRefresh(); //獲取新的beanFactory,銷毀原有beanFactory、為每個bean生成BeanDefinition等 ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory(); // Prepare the bean factory for use in this context. prepareBeanFactory(beanFactory); try { //配置標準的beanFactory,設置ClassLoader,設置SpEL表達式解析器,添加忽略注入的接口,添加bean,添加bean后置處理器等postProcessBeanFactory(beanFactory);// 實例化并調用所有注冊的beanFactory后置處理器(實現接口BeanFactoryPostProcessor的bean,在beanFactory標準初始化之后執行)。StartupStep beanPostProcess = this.applicationStartup.start('spring.context.beans.post-process');// Invoke factory processors registered as beans in the context.invokeBeanFactoryPostProcessors(beanFactory);//實例化和注冊beanFactory中擴展了BeanPostProcessor的bean。registerBeanPostProcessors(beanFactory);beanPostProcess.end(); //初始化國際化工具類MessageSourceinitMessageSource(); //初始化事件廣播器initApplicationEventMulticaster(); //模板方法,在容器刷新的時候可以自定義邏輯,不同的Spring容器做不同的事情。onRefresh(); //注冊監聽器,廣播early application eventsregisterListeners(); //實例化所有剩余的(非懶加載)單例//實例化的過程各種BeanPostProcessor開始起作用。finishBeanFactoryInitialization(beanFactory); //refresh做完之后需要做的其他事情。//清除上下文資源緩存(如掃描中的ASM元數據)//初始化上下文的生命周期處理器,并刷新(找出Spring容器中實現了Lifecycle接口的bean并執行start()方法)。//發布ContextRefreshedEvent事件告知對應的ApplicationListener進行響應的操作finishRefresh(); } catch (BeansException ex) {if (logger.isWarnEnabled()) { logger.warn('Exception encountered during context initialization - ' + 'cancelling refresh attempt: ' + ex);}// Destroy already created singletons to avoid dangling resources.destroyBeans();// Reset ’active’ flag.cancelRefresh(ex);// Propagate exception to caller.throw ex; } finally {// Reset common introspection caches in Spring’s core, since we// might not ever need metadata for singleton beans anymore...resetCommonCaches();contextRefresh.end(); }} }

Spring5學習之基礎知識總結

三級緩存

Spring5學習之基礎知識總結

到此這篇關于Spring5學習之基礎知識總結的文章就介紹到這了,更多相關Spring5知識總結內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
主站蜘蛛池模板: 久久超级碰 | 国产精品免费看久久久香蕉 | 免费a级在线观看播放 | 久久亚洲私人国产精品va | 色秀视频在线观看88品善网 | 久久久久一级片 | 国产欧美综合精品一区二区 | 成人在线免费观看网站 | 一级片免费视频 | 免费一级欧美片在线观免看 | 久久视频在线免费观看 | 九九九热在线精品免费全部 | 日韩毛片在线播放 | jiz欧美高清| 欧美大屁股精品毛片视频 | 欧美一级淫片免费播放口 | 日韩欧美在线观看一区 | 日本色综合网 | 伊人爱爱网| 久久精品成人国产午夜 | 美女视频黄a视频免费全程 美女视频黄a视频免费全过程 | 亚洲欧洲一区二区三区久久 | 亚洲成aⅴ人在线观看 | 国产午夜精品一区二区三区不卡 | 日韩欧美中文字幕在线播放 | 久久精品中文字幕第一页 | 在线免费观看一区二区三区 | 日韩美香港a一级毛片 | 全部孕妇毛片丰满孕妇孕交 | 99热播 | 国产美女在线精品亚洲二区 | 狠狠综合久久久综合 | 久久精品一区二区影院 | 久草视频在线首页 | 性做久久久久久免费观看 | 亚洲综合一区二区不卡 | 在线免费自拍 | 国产一区二区三区四区五区 | 久久精品亚洲综合一品 | 成人 在线欧美亚洲 | 亚洲精品不卡午夜精品 |