Spring的配置及jar包下载
一、相关说明
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包下载的更多相关文章
- maven 项目 pom.xml文件中配置的jar包下载报错
[ERROR] [ERROR] Some problems were encountered while processing the POMs:[ERROR] 'dependencies.depen ...
- log4j 日志配置和jar包下载
1.日志log4j文件配置 ${webapp.root}才是项目根目录log4j.appender.logfile.File= ${catalina.home}/log/filter.log 指生成日 ...
- Spring所需的Jar包下载
作者:zhidashang 来源:CSDN 原文:https://blog.csdn.net/zhidashang/article/details/78706027 版权声明:本文为博主原创文章,转载 ...
- Maven远程仓库:pom依赖以及jar包下载
Maven远程仓库:pom依赖xml配置以及jar包下载: 地址1: http://mvnrepository.com/ 地址2: http://172.16.163.52:8081/nexus/#w ...
- Maven的默认中央仓库以及修改默认仓库&配置第三方jar包从私服下载
当构建一个Maven项目时,首先检查pom.xml文件以确定依赖包的下载位置,执行顺序如下: 1.从本地资源库中查找并获得依赖包,如果没有,执行第2步. 2.从Maven默认中央仓库中查找并获得依赖包 ...
- 转:Maven的默认中央仓库以及修改默认仓库&配置第三方jar包从私服下载
当构建一个Maven项目时,首先检查pom.xml文件以确定依赖包的下载位置,执行顺序如下: 1.从本地资源库中查找并获得依赖包,如果没有,执行第2步. 2.从Maven默认中央仓库中查找并获得依赖包 ...
- Spring、MyBatis和SpringMVC整合的jar包下载
spring mvc的jar包下载:http://repo.springsource.org/libs-release-local/org/springframework/spring/我下载的5.0 ...
- Spring框架针对dao层的jdbcTemplate操作crud之delete删除数据库操作 Spring相关Jar包下载
首先,找齐Spring框架中IoC功能.aop功能.JdbcTemplate功能所需的jar包,当前13个Jar包 1.Spring压缩包中的四个核心JAR包,实现IoC控制反转的根据xml配置文件或 ...
- 2022最新版超详细的Maven下载配置教程、IDEA中集成maven(包含图解过程)、以及导入项目时jar包下载不成功的问题解决
文章目录 1.maven下载 2.maven环境变量的配置 3.查看maven是否配置成功 4.配置文件的修改 5.IDEA集成maven 6.导入项目时jar包下载不成功的问题解决 maven教程: ...
随机推荐
- ACM学习历程—Codeforces 446C DZY Loves Fibonacci Numbers(线段树 && 数论)
Description In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence ...
- codevs 1531山峰
传送门 1531 山峰 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description Rocky山脉有n个山峰,一字排开,从西向东 ...
- bzoj 1657 [Usaco2006 Mar]Mooo 奶牛的歌声——单调栈水题
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1657 #include<iostream> #include<cstdio ...
- Selenium Webdriver元素定位
http://www.cnblogs.com/qingchunjun/p/4208159.html
- Poll: Most Americans&n…
Most Americans support tough new measures to counter gun violence, including banning assault weapons ...
- sublime取消自动升级提示
1.进入Preferences -> Settings-User ,添加 "update_check": false, 2.重启Sublime.
- 如何查看Mysql event事件是否启用
mysql> show variables like 'event_scheduler';+-----------------+-------+| Variable_name | Value ...
- php+redis实现高并发模拟下单、秒杀、抢购操作
对于高并发下的场景,一般都是采用redis缓存机制来处理. 当然也不是只有redis可以处理.还有利用mysql事务操作锁住操作的行.文件锁. 不过这些方式都没有redis缓存高效.可靠. 模拟的过程 ...
- Halcon - 图像随 HWindowControl 控件缩放的同时,保持图像的长宽比例不变
背景 通常情况下,图像是填充满 HWindowControl 控件,并随其缩放的.此时只需要将 set_part 的参数设置成图像的大小即可. 不过,有时候,在一些测量任务中,我们对原始图像的长宽比敏 ...
- RPC原理与实践(二)----Thrift分层模型
这一节我们从一下几个方面来讲一下Thrift的分层架构,按照官方的定义这是Thrift的网络栈,其中网络栈中分为一下几个部分,(由栈顶到栈底)server,processor,protocol,tra ...