Spring的底層搭建原理講解,作開發的均可以看看,對新手極爲友好!

前言

簡單的說一下spring的搭建流程,內容偏基礎,底子很差的能夠看一下!java

配置Maven

如圖所示:找到以前準備好的文件路徑面試

流程

一、新建UserService接口
二、新建UserService實現類
三、經過bean將UserService放入容器
四、經過context的getbean方法拿到UserService對象spring

加載基礎包:

代碼以下:express

<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>5.2.13.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>5.2.13.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>5.2.13.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-expression -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-expression</artifactId>
    <version>5.2.13.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-aop -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aop</artifactId>
    <version>5.2.13.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jcl -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jcl</artifactId>
    <version>5.2.13.RELEASE</version>
</dependency>

後刷新Maven.架構

配置文件

內容:

<?xml version="1.0" encoding="UTF-8"?>
  <beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:util="http://www.springframework.org/schema/util"
   xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    https://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/util
    https://www.springframework.org/schema/util/spring-util.xsd
   ">
   </beans>

點右上角提示的「Configure application context」就能夠了。
app

編寫代碼學習

接口類

代碼以下
測試

新建class文件UserServiceImpl
spa

實現

配置文件

寫mian方法

public class DemoTest {
public static void main(String[] args){
    ApplicationContext context = new ClassPathXmlApplicationContext
            ("classpath:applicationContext.xml");
    UserSvice service = (UserSvice) context.getBean("userService");
    service.saveUser();
}
}

如圖:
運行mian方法,code

測試結果爲

最後

在文章的最後做者爲你們整理了不少資料!包括java核心知識點+全套架構師學習資料和視頻+一線大廠面試寶典+面試簡歷模板+阿里美團網易騰訊小米愛奇藝快手嗶哩嗶哩面試題+Spring源碼合集+Java架構實戰電子書等等!歡迎關注公衆號:前程有光,自行下載!

相關文章
相關標籤/搜索