spring中的ioc
来源:互联网 发布:公共安全与大数据 编辑:程序博客网 时间:2024/05/21 14:08
做java后台有一段时间了,其实涉及到的技术最多的还是spring、springmvc、maven、mybatis。今天主要说一下spring中的ioc。
spring主要的两个性质就是ioc(控制反转)以及aop(面向切面)
ioc其实可以这样理解,就是我需要一套房子,我属于一个类,这房子也属于一个类,我需要房子是一个套二的,简单装修的,有独卫,
有厕所的,然后房屋中介就给我找了一个类似的房子。所以不需要我自己去找这个房子。ioc就是起到房屋中介的作用。
简单代码:
一、定义一个接口
public interface service{public void findHouse();}
二、实现接口方法
public class serviceImpl{public void findHouse(){System.out.println("简单住房");}}
三、接下来是配置文件service.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: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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- id 表示组件的名字,class表示组件类 --> <bean id="helloService" class="com.zzq.test.serviceImpl" /> </beans>
四、ioc调用(获取ioc容器)
public class test{@Testpublic void testService(){ApplicationContext context=new ClassPathXmlApplicationContext(service.xml);serviceImpl service=context.getBean("service",service.class);service.findHouse();}}
0 0
- Spring中的IOC原理
- Spring中的IOC
- spring中的ioc
- Spring中的IOC原理
- Spring中的IOC
- Spring中的IOC实现
- Spring中的IOC
- Spring中的Ioc
- spring中的ioc
- Spring中的IoC
- Spring中的IOC
- Spring中的IOC原理
- spring中的IOC
- Spring中的ioc
- Spring中的IOC
- spring中的ioc
- Spring框架中的Ioc
- spring中的AOP与IOC
- IOS中自定义cell大小的两种方法
- 轮播
- 2016秋招面经
- Eclipse SVN文件对比详解
- 【转】如何在Windows下使用LAPACK和ARPACK
- spring中的ioc
- ByteArrayOutputStream
- Git for Windows安装和基本设置
- Java代码块执行顺序
- flash-connect模块
- Android中Intent的详细用法
- FragmentPagerAdapter和FragmentStatePagerAdapter的区别
- 学习笔记 C++ 封装(上)
- 串口通信模块5:串口操作自定义类(2)