Spring3开发实战 之 第二章:IoC/DI开发(2)
私塾在线老师出品,品质值得信赖
地址:http://sishuok.com/product/181
还有免费课程:http://sishuok.com/presentcourse
=============广告==============================
- <bean id="moreComplexObject" class="example.ComplexObject">
- <property name="adminEmails">
- <props>
- <prop key="administrator">admin@somecompany.org</prop>
- <prop key="support">support@somecompany.org</prop>
- </props>
- </property>
- <property name="someList">
- <list>
- <value>a list element followed by a reference</value>
- <ref bean="myDataSource" />
- </list>
- </property>
- <property name="someMap">
- <map>
- <entry>
- <key> <value>yup an entry</value> </key>
- <value>just some string</value>
- </entry>
- <entry>
- <key> <value>yup a ref</value> </key>
- <ref bean="myDataSource" />
- </entry>
- </map>
- </property>
- <property name="someSet">
- <set>
- <value>just some string</value>
- <ref bean="myDataSource" />
- </set>
- </property>
- </bean>
- <beans>
- <bean id="parent" abstract="true" class="example.ComplexObject">
- <property name="adminEmails">
- <props>
- <prop key="administrator">administrator@somecompany.com</prop>
- <prop key="support">support@somecompany.com</prop>
- </props>
- </property>
- </bean>
- <bean id="child" parent="parent" class= " example.Child" >
- <property name="adminEmails">
- <props merge="true">
- <prop key="sales">sales@somecompany.com</prop>
- <prop key="support">support@somecompany.co.uk</prop>
- </props>
- </property>
- </bean>
- <beans>
- <property name="myProperty">
- <value>hello</value>
- </property>
- <property name="myProperty">
- <ref bean="myBean">
- </property>
- <entry>
- <key>
- <ref bean="myKeyBean" />
- </key>
- <ref bean="myValueBean" />
- </entry>
- <bean id="foo" class="foo.Bar">
- <property name="fred.bob.sammy" value="123" />
- </bean>
- 表示foo
bean有个fred属性,此属性有个bob属性,而bob属性又有个sammy属性,最后把sammy属性设置为123。为了让此定义能工作, foo的fred属性及fred的bob属性在bean被构造后都必须非空,否则将抛出NullPointerException异常。
- <bean id="beanOne" class="ExampleBean" depends-on="manager"/>
- <bean id="manager" class="ManagerBean" />
- <bean id="beanOne" class="ExampleBean" depends-on="manager,accountDao">
- <property name="manager" ref="manager" />
- </bean>
- <bean id="manager" class="ManagerBean" />
- <bean id="accountDao" class="x.y.jdbc.JdbcAccountDao" />
- <web-app>
- <listener>
- <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
- </listener>
- </web-app>
- Java类
- public abstract class HelloImpl implements HelloApi{
- private T2 t2;
- public String helloSpring3(int a){
- getT2().t1();
- System.out.println("hello Spring3==="+a);
- return "Ok,a="+a;
- }
- public abstract T2 getT2();
- }
- public class T2 {
- public void t1(){
- System.out.println("now in t1");
- }
- }
- <bean id="helloBean" class="cn.javass.Spring3.hello.HelloImpl">
- <lookup-method name="getT2" bean="t2"/>
- </bean>
- <bean id="t2" class="cn.javass.Spring3.hello.T2"></bean>
- <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
- <property name="basenames">
- <list>
- <value>format</value>
- <value>exceptions</value>
- </list>
- </property>
- </bean>
- 消息文件:testmsg=this is a test,{0},{1}
- Java类:String msg = context.getMessage("testmsg",
- ew Object[]{"M1","M2"},"Default", Locale.CHINA);
- System.out.println("msg="+msg);
- public class HelloImpl implements HelloApi{
- private MessageSource ms = null;
- public void setMs(MessageSource ms){
- this.ms = ms;
- }
- public String helloSpring3(int a){
- String msg = this.ms.getMessage("testmsg", null, "Default", Locale.CHINA);
- System.out.println("hello Spring3==="+msg);
- return "Ok,a="+a;
- }
- }
- <bean id="helloBean" class="cn.javass.Spring3.hello.HelloImpl">
- <property name="ms" ref="messageSource"></property>
- </bean>
- public class T2 implements ApplicationListener{
- @Override
- public void onApplicationEvent(ApplicationEvent arg0) {
- System.out.println("事件发生了=="+arg0);
- }
- }
- public interface Resource extends InputStreamSource {
- boolean exists();
- boolean isOpen();
- URL getURL() throws IOException;
- File getFile() throws IOException;
- Resource createRelative(String relativePath) throws IOException;
- String getFilename();
- String getDescription();
- }
- public interface InputStreamSource {
- InputStream getInputStream() throws IOException;
- }
- InputStream in = context.getResource("msg_en_GB.properties").getInputStream();
- byte bs[] = new byte[100];
- in.read(bs);
- System.out.println("file content=="+new String(bs));
- private Resource rs = null;
- public void setRs(Resource rs){
- this.rs = rs;
- }
- <bean id="helloBean" class="cn.javass.Spring3.hello.HelloImpl">
- <property name="rs" value="msg_en_GB.properties"></property>
- </bean>
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml</param-value>
- </context-param>
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
Spring3开发实战 之 第二章:IoC/DI开发(2)相关推荐
- 【项目开发实战】第二章——在线商城系统
系列文章目录 第一章--AI人机对战版五子棋游戏 第二章--在线商城系统 文章目录 系列文章目录 前言 1.项目介绍 2.项目规划分析 2.1 电子商务的简要介绍 2.2 在线博客+商城系统构成模块 ...
- DirectX 12 3D游戏开发实战 (第二章 矩阵代数)
目录 矩阵代数 2.1 矩阵的定义 2.2 矩阵乘法 2.3 转置矩阵 2.4 单位矩阵 2.5 矩阵的行列式 2.6 伴随矩阵 2.7 逆矩阵 2.8 用DirectXMath库处理矩阵 矩阵代数 ...
- 《Python3网络爬虫开发实战(第二版)》上市了!!!!
" 阅读本文大概需要 5 分钟. " 告诉大家一个好消息:我的好朋友崔庆才老师的<Python3网络爬虫开发实战(第二版)>现在正式上市了!!!! 没错,就是这本: 就 ...
- 《Python3网络爬虫开发实战(第二版)》内容介绍
这是「进击的Coder」的第 505 篇分享 作者:崔庆才 大家好,本节首先来预告下即将出版的<Python3网络爬虫开发实战(第二版)>的主要内容. 由于我已经把书的总体的内容介绍写在了 ...
- Xamarin iOS开发实战第1章使用C#编写第一个iOS应用程序
Xamarin iOS开发实战第1章使用C#编写第一个iOS应用程序 C#原本是用来编写Windows以及Windows Phone的应用程序.自从Xamarin问世后,C#的作用就发生了很大的变化. ...
- 第二章 java常用开发工具以及程序的编写
2019独角兽企业重金招聘Python工程师标准>>> 第二章 java常用开发工具以及程序的编写 1. 程序的概念 2. java程序的开发的三个步骤 ...
- ASP.NET3.5 企业级项目开发 -- 第二章(续) 数据访问层(DAL)的开发解决方案提出...
ASP.NET3.5 企业级项目开发 -- 第二章(续) 数据访问层(DAL)的开发解决方案提出 前言:首先给大家说声"对不起",因为自从打算写这系列的文章以来,得到大家很多的支持 ...
- ASP.NET3.5 企业级项目开发 -- 第二章 数据访问层(DAL)的开发
为什么80%的码农都做不了架构师?>>> ASP.NET3.5 企业级项目开发 -- 第二章 数据访问层(DAL)的开发 前言:本篇主要讲述数据访问层的开发, ...
- 慕课嵌入式开发及应用(第二章.嵌入式硬件构件与底层驱动构件基本规范)
慕课苏州大学.嵌入式开发及应用.第二章.入门与软件框架.嵌入式硬件构件与底层驱动构件基本规范 0 目录 2 入门与软件框架 2.1 嵌入式硬件构件与底层驱动构件基本规范 2.1.1 课堂重点 2.1. ...
- 《Python3 网络爬虫开发实战(第二版)》第二波赠书获奖名单公布~
" 阅读本文大概需要 3 分钟. " 上周我搞了一个赠书活动,详情见:618 来了!<Python3网络爬虫开发实战(第二版)>第二波赠书活动也来了!,真的非常感谢大家 ...
最新文章
- opencv python 官方文档里的“sa”关键字是什么意思?(see also)
- 2018.12.08 codeforces 939E. Maximize!(二分答案)
- 使用Pytorch进行密集视频字幕
- 【转载】优秀文章转载集合
- C语言base64编解码
- Flask笔记-通过Model访问数据库
- ICallbackEventHandler不支持二次回调的问题
- Transformer 的稳健性更好吗?
- 机器学习实战6-sklearn训练决策树实现分类和回归
- php 去掉script,php怎么去除js
- java file.length 单位_Java.io.File.length()返回0
- 实习成长之路:操作系统——CPU有哪些工作模式呢?
- 基于Php+MySql数据库架构的网络验证系统
- 发现IGame中又一个大坑
- DD每周前端七题详解-第五期
- html table 实现表头固定
- 如何利用互联网了解你的客户
- 读者网作者发布次数统计爬虫(三种实现方法)
- 苹果cms源码支持php版本_最新影视小程序对接苹果cms详细教程+源码[无授权完美运营版本]...
- 饥荒联机服务器修改冬天时间,饥荒联机版永冬永夜世界设置技巧_饥荒联机版世界怎么设置_牛游戏网...