一、相关说明

IOC:

Inversion of Control,控制反转,是面向对象编程中的一种设计原则,可以用来减低计算机代码之间的耦合度。其中最常见的方式叫做依赖注入(Dependency Injection,简称DI)。通过控制反转,对象在被创建的时候,由一个调控系统内所有对象的外界实体将其所依赖的对象的引用传递给它。也可以说,依赖被注入到对象中。简单地说就是拿到的对象的属性,已经被注入好相关值了,直接使用即可。

AOP

在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术。

Spring是一个基于IOC和AOP的结构J2EE系统的框架

二、配置Spring

1、新建java类型项目

2、导入jar包

现在Spring是放在github上托管,下载步骤如下:

a、进入spring官网点击project

b、springfarmework

c、点右边github标志

d、底部的artifacts

e、Spring Artifactory

f、三个版本,一般选第三个,稳定些

g、依次选择org/springfarmework/spring,然后选择需要的版本

3、将包导入到项目中

4、在src下建包,新建一个Category类

package com.yyt.pojo;

public class Category {
private int id;
private String name; public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
} }

5、在src目录下新建applicationContext.xml文件

applicationContext.xml是Spring的核心配置文件,通过关键字c即可获取Category对象,该对象获取的时候,即被注入了字符串"category 1“到name属性中

<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <bean name="c" class="com.yyt.pojo.Category"> <property name="name" value="category 1" /> </bean> </beans>

6、test类

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.how2java.pojo.Category; public class Test { public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
new String[] { "applicationContext.xml" }); Category c = (Category) context.getBean("c"); System.out.println(c.getName());
}
}

三、原理

传统的方式:
通过new 关键字主动创建一个对象
IOC方式
对象的生命周期由Spring来管理,直接从Spring那里去获取一个对象。 IOC是反转控制 (Inversion Of Control)的缩写,就像控制权从本来在自己手里,交给了Spring。

注:基于框架的程序要成功运行,对于JAR包的版本,配置文件的正确性有着苛刻的要求,任何一个地方出错了,都会导致框架程序运行失败。

Spring的配置及jar包下载的更多相关文章

  1. maven 项目 pom.xml文件中配置的jar包下载报错

    [ERROR] [ERROR] Some problems were encountered while processing the POMs:[ERROR] 'dependencies.depen ...

  2. log4j 日志配置和jar包下载

    1.日志log4j文件配置 ${webapp.root}才是项目根目录log4j.appender.logfile.File= ${catalina.home}/log/filter.log 指生成日 ...

  3. Spring所需的Jar包下载

    作者:zhidashang 来源:CSDN 原文:https://blog.csdn.net/zhidashang/article/details/78706027 版权声明:本文为博主原创文章,转载 ...

  4. Maven远程仓库:pom依赖以及jar包下载

    Maven远程仓库:pom依赖xml配置以及jar包下载: 地址1: http://mvnrepository.com/ 地址2: http://172.16.163.52:8081/nexus/#w ...

  5. Maven的默认中央仓库以及修改默认仓库&配置第三方jar包从私服下载

    当构建一个Maven项目时,首先检查pom.xml文件以确定依赖包的下载位置,执行顺序如下: 1.从本地资源库中查找并获得依赖包,如果没有,执行第2步. 2.从Maven默认中央仓库中查找并获得依赖包 ...

  6. 转:Maven的默认中央仓库以及修改默认仓库&配置第三方jar包从私服下载

    当构建一个Maven项目时,首先检查pom.xml文件以确定依赖包的下载位置,执行顺序如下: 1.从本地资源库中查找并获得依赖包,如果没有,执行第2步. 2.从Maven默认中央仓库中查找并获得依赖包 ...

  7. Spring、MyBatis和SpringMVC整合的jar包下载

    spring mvc的jar包下载:http://repo.springsource.org/libs-release-local/org/springframework/spring/我下载的5.0 ...

  8. Spring框架针对dao层的jdbcTemplate操作crud之delete删除数据库操作 Spring相关Jar包下载

    首先,找齐Spring框架中IoC功能.aop功能.JdbcTemplate功能所需的jar包,当前13个Jar包 1.Spring压缩包中的四个核心JAR包,实现IoC控制反转的根据xml配置文件或 ...

  9. 2022最新版超详细的Maven下载配置教程、IDEA中集成maven(包含图解过程)、以及导入项目时jar包下载不成功的问题解决

    文章目录 1.maven下载 2.maven环境变量的配置 3.查看maven是否配置成功 4.配置文件的修改 5.IDEA集成maven 6.导入项目时jar包下载不成功的问题解决 maven教程: ...

随机推荐

  1. PHP函数---$_Get()和$_Post()的用法

    一.$_Get()和$_Post()函数是用来传值的,即对应两种提交表单的方法,get和post. 二.$_Get方法 (1)获取通过URL的传值 Example 1 新建两个PHP文件,1.php, ...

  2. nginx web端口映射

    nginx web端口映射 举例: 问:在一台有外网的宿主机上部署了一个kvm虚拟机,在虚拟机上部署了web,需要外网访问此web,但虚拟机只有内网ip,只和宿主机通,怎么实现外网访问web服务? 答 ...

  3. Java面试知识点总结(1)

    1.Java中的原始数据类型都有哪些,它们的大小及对应的封装类是什么? 原始数据类型 大小(byte) 对应封装类型 boolean 1或4 Boolean byte 1 Byte short 2 S ...

  4. ReportEvent的正确使用方式

    向操作系统的事件管理器报告重大信息是一种非常有用的方式,特别是对于没有界面的后台服务而言.如果你对Windows编程有一定了解,应该很快就能想到使用ReportEvent这个API,然后快速写出下面的 ...

  5. MySQL 的索引和最左前缀原则

    这两天看<构建高性能Web站点>这本书,感觉写的真是不错,很多实际项目中会碰到的问题都有所提及,今天看到一个最左前缀原则,以前也听说过,不过一直没搞明白,今天查了下. 通过实例理解单列索引 ...

  6. (二)搭建SSH环境

    一.struts 1.添加jar包: commons-fileupload-1.3.1.jar,[文件上传相关包] commons-io-2.2.jar, commons-lang-2.4.jar , ...

  7. linux下c语言利用iconv函数实现utf-8转unicode

    iconv是linux下的编码转换的工具,它提供命令行的使用和函数接口支持 man手册iconv命令用法如下: iconv -f encoding -t encoding inputfile 有如下选 ...

  8. VS2015中使用Git遇到问题 Cannot do push / pull in git - working with visual studio

    I have made a lot of changes, when I am trying to push them - I am getting the next error: You canno ...

  9. PHP注释-----PHPDOC

    用过IDE或看过其他源码的小伙伴们应该都见过类似下面这样的注释   /** * 递归获取所有游戏分类 * @param int $id * @return array */ 看得多了就大概知道了一些规 ...

  10. 3dmax室内设计,建筑视频

    第一教程篮球场 http://video.1kejian.com/video/?30800-0-1.html 第一课 元素级别-flip反转(直接看模型里面) 第二课 alt+r = ring crt ...