查看“Spring:IOC”的源代码
←
Spring:IOC
跳到导航
跳到搜索
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
[[category:SpringFramework]] == 关于IOC == IOC:Inversion of Control '''控制反转''',指的是'''对象的创建权反转(交给)给Spring''',作用是实现了程序的解耦合。 [[File:IOC 的底层实现原理.jpg|1000px]] 下载: * 官网:“http://spring.io/” * 下载地址:“http://repo.springsource.org/libs-release-local/org/springframework/spring” Spring 目录结构: * docs:API 和开发规范 * libs:jar 包和源码 * schema:约束 相关jar: :[[File:IOC相关jar包.jpg|400px]] : 即“core container”的四个部分; :[[File:SpringFramework Runtime.jpg|600px]] == 使用示例 == # 创建web 项目 # 引入Spring 的开发包 # 相关配置文件: ## log4j.properties:日志配置 ## applicationContext.xml:Spring配置文件: ##* (配置说明,位于包的doc中:“spring-framework-4.2.4.RELEASE\docs\spring-framework-reference\html\xsd-configuration.html”) ##: <syntaxhighlight lang="xml"> <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.xsd"> </beans> </syntaxhighlight> # 编写相关的类: #: <syntaxhighlight lang="java"> public interface UserDao { public void sayHello(); } public class UserDaoImpl implements UserDao { @Override public void sayHello() { System.out.println("Hello Spring..."); } } </syntaxhighlight> # 完成配置: #: <syntaxhighlight lang="xml"> <!-- Spring 的入门案例 --> <bean id="userDao" class="cn.itcast.spring.demo1.UserDaoImpl"></bean> </syntaxhighlight> # 编写测试程序: #: <syntaxhighlight lang="java"> @Test // Spring 的方式: public void demo2(){ // 创建Spring 的工厂类: ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml"); // 通过工厂解析XML 获取Bean 的实例. UserDao userDao = (UserDao) applicationContext.getBean("userDao"); userDao.sayHello(); } </syntaxhighlight> == Bean的管理:XML == == Bean的管理:注解 == == Bean的属性注入(DI) ==
返回至“
Spring:IOC
”。
导航菜单
个人工具
登录
命名空间
页面
讨论
大陆简体
已展开
已折叠
查看
阅读
查看源代码
查看历史
更多
已展开
已折叠
搜索
导航
首页
最近更改
随机页面
MediaWiki帮助
笔记
服务器
数据库
后端
前端
工具
《To do list》
日常
阅读
电影
摄影
其他
Software
Windows
WIKIOE
所有分类
所有页面
侧边栏
站点日志
工具
链入页面
相关更改
特殊页面
页面信息