Spring學習文檔——利用maven搭建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)創建一個對象

 

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

任意位置(建議src下)

配置文件名任意(建議applicationContext.xml)

導入約束

Spring中配置

測試

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章