Spring学习(一)
来源:互联网 发布:国外语音聊天软件 编辑:程序博客网 时间:2024/06/05 11:21
一、Spring了解
基本了解:spring最为熟知的几个功能:依赖注入/控制反转 和 面向切面编程
在Spring中有许多的容器,在以前都是使用Bean工厂,但是现在基本都是使用应用
上下文
下面是几种常用的应用上下文加载方式:
ClassPathXmlApplicationContext:通过加载类路径下的xml文件,最常使用的方
式,即加载src目录下的bean.xml文件。
FileSystemXmlApplicationContext:通过指定绝对路径加载配置文件。
XmlWebApplicationContext:读取web应用下的配置文件加载。
二、第一个Spring实例
package com.firstSpring;public interface Helloworld { public String sayHi();}
package com.firstSpring;public class HelloWorldImpl implements Helloworld { @Override public String sayHi() { return "firstSpring"; }}
package com.firstSpring;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class TestMain { public static void main(String[] args) { //1:创建Spring的IOC容器对象 ApplicationContext apc=new ClassPathXmlApplicationContext("springXML/beans.xml"); //2:从IOC容器中获取Bean实例 Helloworld hello=(Helloworld) apc.getBean("helloWorld"); System.out.println(hello.sayHi()); }}
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="helloWorld" class="com.firstSpring.HelloWorldImpl"></bean></beans>
阅读全文
0 0
- Spring学习(一)
- Spring学习(一)
- Spring学习(一)
- Spring学习(一)
- Spring学习(一)
- Spring学习(一)
- Spring学习(一)
- Spring 学习(一)
- Spring学习(一)
- spring学习(一)
- spring学习(一)
- Spring 学习(一)
- spring 学习(一)
- Spring学习(一)
- Spring学习(一)
- Spring学习(一)
- Spring学习系列-----(一)Spring概述
- 【Spring学习笔记】Spring事务管理(一)
- STM32启动BOOT0 BOOT1设置方法
- 第一篇博客
- I2C总线的使用 --- EEPROM 存储器使用
- Mongodb 实战优化
- Hibernate入门
- Spring学习(一)
- CSU-ACM2017暑期训练7-模拟&&贪心 E
- javascript基础
- JavaScript对象
- HDU6077 2017杭电多校联赛第四场-Time To Get Up
- (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
- 集合深浅拷贝以及经常遇到的坑
- C++学习之string类
- 自定义View画圆并移动