Spring入门详细教程(一)

 

一、spring概述

Spring是一个开放源代码的设计层面框架,他解决的是业务逻辑层和其他各层的松耦合问题,因此它将面向接口的编程思想贯穿整个系统应用。Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson创建。简单来说,Spring是一个分层的JavaSE/EE full-stack(一站式) 轻量级开源框架。

二、Spring特点

1、方便解耦,简化开发。

2、AOP编程的支持。

3、声明式事务的支持。

4、方便程序的测试

5、方便集成各种优秀框架

三、spring下载

下载地址:https://repo.spring.io/libs-release-local/org/springframework/spring/

进入后可选择下载版本,选择版本后,进入目录结构。其中dist是最终发布版本,包含开发所需lib和源码。docs是开发文档。schema是一些约束文件。

四、spring搭建入门案例

1、在eclipse中创建一个动态的web工程。

2、导入spring的基础lib包到lib文件夹下。

3、编写一个实体User类

复制代码
package com.jichi.entity;  public class User {     private String name;     private Integer age ;     public String getName() {         return name;     }     public void setName(String name) {         this.name = name;     }     public Integer getAge() {         return age;     }     public void setAge(Integer age) {         this.age = age;     } }
复制代码

4、创建applicationContext.xml文件

在src文件下,新建applicationContext.xml文件,同时引入约束。

复制代码
<?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"     xmlns:jee="http://www.springframework.org/schema/jee"     xmlns:lang="http://www.springframework.org/schema/lang"     xmlns:jms="http://www.springframework.org/schema/jms"     xmlns:aop="http://www.springframework.org/schema/aop"     xmlns:tx="http://www.springframework.org/schema/tx"     xmlns:context="http://www.springframework.org/schema/context"     xmlns:jdbc="http://www.springframework.org/schema/jdbc"     xmlns:cache="http://www.springframework.org/schema/cache"     xmlns:mvc="http://www.springframework.org/schema/mvc"     xmlns:oxm="http://www.springframework.org/schema/oxm"     xmlns:task="http://www.springframework.org/schema/task"     xmlns:tool="http://www.springframework.org/schema/tool"     xmlns:websocket="http://www.springframework.org/schema/websocket"     xsi:schemaLocation="         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd        http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd 
                    
50000+
5万行代码练就真实本领
17年
创办于2008年老牌培训机构
1000+
合作企业
98%
就业率

联系我们

电话咨询

0532-85025005

扫码添加微信