天天看點

Spring學習文檔——利用maven搭建Spring環境Spring搭建

Spring搭建

1.導入依賴包

建立一個quickStart Maven工程。

在pom.xml中引入搭建Spring架構所需要的四個基礎的包,與一個日志包。

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

    <!-- 日志包https://mvnrepository.com/artifact/log4j/log4j -->
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
</dependencies>
           

2.測試

(1)建立一個對象

Spring學習文檔——利用maven搭建Spring環境Spring搭建

(2)書寫配置注冊對象到容器

任意位置(建議src下)

配置檔案名任意(建議applicationContext.xml)

導入限制

Spring中配置

Spring學習文檔——利用maven搭建Spring環境Spring搭建

測試

Spring學習文檔——利用maven搭建Spring環境Spring搭建

繼續閱讀