天天看點

Spring架構搭建(入門級别)

環境準備:

Eclipse

1、建立項目:File--New--Dynamic Web Project:

Spring架構搭建(入門級别)

建立的項目後為:

Spring架構搭建(入門級别)

2、導入jar包:下載下傳spring的jar包以及common-log.jar包

下載下傳方法:spring的jar包:連結:https://pan.baidu.com/s/1AdKD980kSURJrc1mtjC4VA

提取碼:6r91

common-log.jar包:連結:https://pan.baidu.com/s/1dvVJ_TBAh3ziOgKCJOE-GQ

提取碼:nbtv

3、建立Student類以及Course類:

Spring架構搭建(入門級别)
Spring架構搭建(入門級别)

接着建立applicationContext.xml,代碼如下:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<bean id="Student" class="entity.Student">  
        <property name="name">  
            <value>Tom</value>  
        </property>  
    </bean>  
    
    <bean id="Course" class="entity.Course">  
        <property name="coursename">  
            <value>Chinese</value>  
        </property>  
    </bean>  

</beans>
           

建立Test.java類,如下:

Spring架構搭建(入門級别)

按照以下的方式進行執行Test檔案,如下所示:

Spring架構搭建(入門級别)