SPRING IN ACTION 第4版笔记-第一章-002-DI介绍
一、
1.knight.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="knight" class="chapter01.sia.knights.BraveKnight">
<constructor-arg ref="quest" />
</bean> <bean id="quest" class="chapter01.sia.knights.SlayDragonQuest">
<constructor-arg value="#{T(System).out}" />
</bean> </beans>
2.Knight
package chapter01.sia.knights;
public interface Knight {
void embarkOnQuest();
}
3.BraveKnight
package chapter01.sia.knights;
public class BraveKnight implements Knight {
private Quest quest;
public BraveKnight(Quest quest) {
this.quest = quest;
}
public void embarkOnQuest() {
quest.embark();
}
}
4.SlayDragonQuest
package chapter01.sia.knights;
import java.io.PrintStream;
public class SlayDragonQuest implements Quest {
private PrintStream stream;
public SlayDragonQuest(PrintStream stream) {
this.stream = stream;
}
public void embark() {
stream.println("Embarking on quest to slay the dragon!");
}
}
5.
package chapter01.sia.knights; import org.springframework.context.support.
ClassPathXmlApplicationContext; public class KnightMain { public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("classpath:knight.xml");
Knight knight = context.getBean(Knight.class);
knight.embarkOnQuest();
context.close();
} }
6.运行
三月 01, 2016 9:42:47 上午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@4ec12ad8: startup date [Tue Mar 01 09:42:47 CST 2016]; root of context hierarchy
三月 01, 2016 9:42:47 上午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [knight.xml]
三月 01, 2016 9:42:47 上午 org.springframework.context.support.ClassPathXmlApplicationContext doClose
信息: Closing org.springframework.context.support.ClassPathXmlApplicationContext@4ec12ad8: startup date [Tue Mar 01 09:42:47 CST 2016]; root of context hierarchy
Embarking on quest to slay the dragon!
SPRING IN ACTION 第4版笔记-第一章-002-DI介绍的更多相关文章
- SPRING IN ACTION 第4版笔记-第一章-005-Bean的生命周期
一. 1. As you can see, a bean factory performs several setup steps before a bean is ready touse. Let’ ...
- SPRING IN ACTION 第4版笔记-第一章-003-AOP介绍
一.目标 要在BraveKnight调用embarkOnQuest()前后各做一些处理(调用Minstrel的方法) 二. 1.minstrel.xml <?xml version=" ...
- Spring In Action 第4版笔记-第一章-001架构
1.Spring’s fundamental mission: Spring simplifies Java development. 2.To back up its attack on Java ...
- SPRING IN ACTION 第4版笔记-第一章-004-用类来管理DI
一. 1. package chapter01.sia.knights.config; import org.springframework.context.annotation.Bean; impo ...
- SPRING IN ACTION 第4版笔记-第九章Securing web applications-011-把敏感信息请求转为https(requiresChannel())
1.把包含敏感信息的请求转为https请求,则较为安全,但如何只把有需要安全的请求转为https,而不是不加分辩就把所有请求都转为https呢?可以用requiresChannel() @Overri ...
- SPRING IN ACTION 第4版笔记-第九章Securing web applications-010-拦截请求
一. What if you wanted to restrict access to certain roles only on Tuesday? Using the access() method ...
- SPRING IN ACTION 第4版笔记-第九章Securing web applications-008-使用非关系型数据库时如何验证用户(自定义UserService)
一. 1.定义接口 Suppose that you need to authenticate against users in a non-relational database suchas Mo ...
- SPRING IN ACTION 第4版笔记-第九章Securing web applications-007-设置LDAP server比较密码(contextSource、root()、ldif()、)
一.LDAP server在哪 By default, Spring Security’s LDAP authentication assumes that the LDAP server is li ...
- SPRING IN ACTION 第4版笔记-第九章Securing web applications-004-对密码加密passwordEncoder
一. 1.Focusing on the authentication query, you can see that user passwords are expected to be stored ...
随机推荐
- 【转】性能测试设计和LR原理的探讨
做了4个迭代的性能测试, 在没有需求的情况下步步艰辛,把代码和框架独立开发从0到一万多行代码的测试工具(脚本),作为性能测试工具佼佼者Lr,我时而拿他作参考,山寨了它很多 东西,同时带有很多疑问对它实 ...
- 首页的sitecontent地址
当无法出现工具栏时,利用url地址,可以方便直接进入sitecontent http://sp2013/sites/bentest/_layouts/15/viewlsts.aspx
- 转载---SQL Server XML基础学习<3>之--FOR XML EXPLICIT
--使用 RAW 和 AUTO 模式不能很好地控制从查询结果生成的 XML 的形状.--但是,对于要从查询结果生成 XML,EXPLICIT 模式会提供非常好的灵活性. --必须以特定的方式编写 EX ...
- swift变量交换赋值
重点在& func jiaohuan(inout a: Int,inout b: Int) { let temp = a a = b b = temp } jiaohuan(&aa,b ...
- 是么是 API 和 SDK
API(Application Programming Interface,应用程序编程接口)是一些预先定义的函数,目的是提供应用程序与开发人员基于某软件或硬件得以访问一组例程的能力,而又无需访问源码 ...
- asp.net:录入数据库的中文变问号
表格是可以接受中文的: 类型也是nvarchar的: 还是出现写中文变问号?? 这时候请加入转义大写N: 如: 原查询语句:insert into table1(name) values('蜘蛛侠' ...
- HDU 1176 免费馅饼(数字三角形)
免费馅饼 Problem Description 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉 ...
- Google Test Frame 简单使用例子
1 序言——为什么折腾Google Test 被逼无奈的. 最近研究google开源的基于列存储的数据库查询引擎supersonic源码.初略的浏览了一遍代码,竟然没有main函数,顿时惊讶的目瞪口呆 ...
- 使用CPA4破解经典密码算法
下面是一段经过经典密码算法加密的密文(加密算法未知): yvvnerujjvnywhbdvkpchfgvjtzwqsuporqfzpoekkjgziicdwwkeejdsruef whwseyej ...
- Linux下通过ODBC连接sqlserver
Linux下通过ODBC连接sqlserver 1.需求: 最近有个需求就是要在linux下连接(可以执行sql语句)sqlserver 2.环境 操作系统: Centos6.5 数据库: ...