Spring 教程(一)


aopalliance-1.0.jarcommons-logging-1.1.1.jarspring-aop-3.2.0.RELEASE.jarspring-beans-3.2.0.RELEASE.jarspring-context-3.2.0.RELEASE.jarspring-core-3.2.0.RELEASE.jarspring-expression-3.2.0.RELEASE.jar
- <?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="userDao" class="com.boya.spring.ioc.UserDao" />
- <bean id="exampleBean" class="com.boya.spring.ioc.ExampleBean">
- <property name="name" value="boya" />
- <property name="userDao" ref="userDao" />
- </bean>
- </beans>
- public class UserDao {
- public String getName() {
- return "boya";
- }
- }
- public class ExampleBean {
- private String name;
- private UserDao userDao;
- public void print(){
- System.out.println("Name is :"+name);
- }
- public void userPrint(){
- System.out.println("User name is :"+userDao.getName());
- }
- //省略getter、setter方法
- }
- ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
- ExampleBean exampleBean = context.getBean("exampleBean", ExampleBean.class);
- exampleBean.print();
- exampleBean.userPrint();
Name is :boyaUser name is :boya
- <?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">
- <context:component-scan base-package="com.boya.spring.ioc" />
- </beans>
- @Repository
- public class UserDao {
- public String getName() {
- return "boya";
- }
- }
- @Service
- public class ExampleBean {
- @Resource
- @Value("boya")
- private String name;
- @Resource
- private UserDao userDao;
- public void print(){
- System.out.println("Name is :"+name);
- }
- public void userPrint(){
- System.out.println("User name is :"+userDao.getName());
- }
- }
- ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
- ExampleBean exampleBean = context.getBean("exampleBean", ExampleBean.class);
- exampleBean.print();
- exampleBean.userPrint();
Name is :boyaUser name is :boya
Spring 教程(一)的更多相关文章
- Spring教程索引
Spring教程索引 2016-11-15 1 入门 1 概述.深入浅出Spring(一)Spring概述 2 体系结构 3 环境设置 4 Hello World 实例 5 IoC 容器 IoC容 ...
- Spring教程:tutorialspoint-spring
来自turorialspoint的Spring教程(英文),官网:https://www.tutorialspoint.com/spring/index.htm 这个教程在国内已经被翻译成中文(不过是 ...
- Spring教程检视阅读
Spring教程检视阅读 地址 可供参考的教程 <菜鸟学 SSH> <Spring Boot 那些事> <初识 Spring Security> <Sprin ...
- 13、Spring教程之全部(包括所有章节)
Spring 教程 1.Spring概述 简介 Spring : 春天 --->给软件行业带来了春天 2002年,Rod Jahnson首次推出了Spring框架雏形interface21框架. ...
- Java系列教程-Spring 教程目录
Spring 教程目录 可参考MyBatis的官方文档也比较清楚 https://mybatis.org/mybatis-3/zh/getting-started.html 代码 目录 https:/ ...
- HowToDoInJava Spring 教程·翻译完成
原文:HowToDoInJava 协议:CC BY-NC-SA 4.0 欢迎任何人参与和完善:一个人可以走的很快,但是一群人却可以走的更远. ApacheCN 学习资源 目录 Spring 5 Spr ...
- spring教程
Spring框架是Java EE开发中最流行的框架,已经成为JEE事实上的标准,全世界的开发人员都在使用Spring框架开发各种应用.随着Spring boot,Spring cloud新版本的不断推 ...
- Spring 教程(二)
一.Spring AOP介绍 开发其实就是在不断的重构,抽象重复代码,然后进行封装.从最原始的模块化编程到面向对象编程,代码的封装越来越整齐清晰,但是依然存在重复的代码,而这些重复代码几乎都是与业务逻 ...
- 【spring教程之二】spring注射剂xml构造方法参数
1.上述续,假设你想注入bean当文件,传递给构造函数的参数.主要的变化是需要spring.xml配置文件来配置. <?xml version="1.0" encoding= ...
随机推荐
- GWT RPC
GWT RPC GWT RPCRemote Procedure Calls GWT: Google Web Toolkit的缩写,有了 GWT可以使用 Java 编程语言编写 AJAX 前端,然后 G ...
- 2733: [HNOI2012]永无乡 - BZOJ
Description 永无乡包含 n 座岛,编号从 1 到 n,每座岛都有自己的独一无二的重要度,按照重要度可 以将这 n 座岛排名,名次用 1 到 n 来表示.某些岛之间由巨大的桥连接,通过桥可以 ...
- 1046: [HAOI2007]上升序列 - BZOJ
Description 对于一个给定的S={a1,a2,a3,…,an},若有P={ax1,ax2,ax3,…,axm},满足(x1 < x2 < … < xm)且( ax1 < ...
- discuz微社区 始终显示“正在加载中”
使用DZ的tools工具一键关闭所有插件后,帮我排查了js冲突的问题,但是也带来了一系列后患: 云平台连“QQ互联”也失效了,之前云平台的各项业务已经不正常,无法开启关闭,提示“远程接口无法调用... ...
- 8 行 Node.js 代码实现代理服务器
接触 Node.js 已有多年,一直喜欢它的单线程模型和异步IO特性,以及 JavaScript 语言本身的灵活性.同时,JavaScript 前后端通吃,在全栈开发领域具有独特的优势.今天就来看看作 ...
- setjump 和 longjump
goto语句可以用于同一个函数内异常处理,不幸的是,goto是本地的,它只能跳到所在函数内部的标号上.为了解决这个限制,C函数库提供了setjmp()和longjmp()函数,它们分别承担非局部标号和 ...
- CodeForces 299A Ksusha and Array
http://codeforces.com/problemset/problem/299/A 题意 :输入n个数,要求找出一个数能让其他所有的数整除,如果没有的话输出-1.有多个的话输出其中一个. 思 ...
- windows8 64位 IIS8 PHP5.5 安装 Imagemagick 组件
为什么这里一定要说 windows 系统是64位呢,因为如果是系统是64位,那么PHP5.5 一般都会选择64的, Imagemagick 组件也会选择64位的, 但是操蛋的是 64位的Imagema ...
- [itint5]Excel数转换
http://www.itint5.com/oj/#23 这里就是26进制的转换,但是要注意没有0,A就是1,Z就是26.所以要想象成从0开始,才能用原来的方法计算. //将十进制数转换为excel数 ...
- ANDROID_MARS学习笔记_S01_003layout初步
一.layout介绍 二.测试linear_layout1.activity_main.xml <?xml version="1.0" encoding="utf- ...