Spring快速搭建环境及简单demo

1.有合适的jdk以及eclipse,下载好完整的spring jar包

2.新建一个网页工程 Dynamic  Web Project

3.导入jar包,将jar包复制到lib文件夹下

Spring快速搭建环境及简单demo_第1张图片

4.新建一个包,其中两个类,一个为配置到spring中用,一个用来测试,这里将pojo类 SpringT放入spring

Spring快速搭建环境及简单demo_第2张图片

5.在src目录下创建一个xml文件(名字不固定,建议为applicationContext.xml,这样后期不需要进行二次配置)

其文件内容固定部分如下(完整版约束):


    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/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd">

 6.将pojo类配置进去

 
         
         
   

7.使用测试类实例化配置文件

Spring快速搭建环境及简单demo_第3张图片

8.结果:

你可能感兴趣的:(spring)