1. Spring is lightweight= minimal impact
2. Spring DI= JavaBeans +interfaces
3.JSR-330=Dependency Injection for Java
4.JSR-303= Bean Validation API specification
5.
props = new Properties(); props.load(new FileInputStream(“ch2/src/conf/msf.properties”)); String rendererClass = props.getProperty(“renderer.class”);6.Injection vs. Lookup
7.<context:annotation-config>tag tells Spring to scan the codebase for dependency requirements.because of <context:annotation-config>tag,during the initialization of Spring’s ApplicationContext, Spring will discover those @Autowired annotations and inject the dependency (discovered via the <context:component-scan>tag) as required.
8.
@Value("John Smith")
private String name;
9.SpringEL
public class InjectSimpleConfig { private String name = "John Smith"; private int age = 35; private float height = 1.78f; private boolean programmer = true; private Long ageInSeconds = 1103760000L; // Getter/setter method omitted }
<bean id="injectSimpleConfig" class="com.apress.prospring3.ch4.xml.InjectSimpleConfig"/> <bean id="injectSimpleSpel" class="com.apress.prospring3.ch4.xml.InjectSimpleSpel"> <property name="name"> <value>#{injectSimpleConfig.name}</value> </property> <property name="age"> <value>#{injectSimpleConfig.age + 1}</value> </property> <property name="height"> <value>#{injectSimpleConfig.height}</value> </property> <property name="isProgrammer"> <value>#{injectSimpleConfig.programmer}</value> </property> <property name="ageInSeconds"> <value>#{injectSimpleConfig.ageInSeconds}</value> </property> </bean>
@Service("injectSimpleSpel") public class InjectSimpleSpel { @Value("#{injectSimpleConfig.name}") private String name; @Value("#{injectSimpleConfig.age + 1}") private int age; @Value("#{injectSimpleConfig.height}") private float height; @Value("#{injectSimpleConfig.programmer}") private boolean programmer; @Value("#{injectSimpleConfig.ageInSeconds}") private Long ageInSeconds; // Other codes omitted }10.Using Collections for Injection
public class CollectionInjection { private Map<String, Object> map; private Properties props; private Set set; private List list; public static void main(String[] args) { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.load("classpath:app-context-xml.xml"); ctx.refresh(); CollectionInjection instance = (CollectionInjection) ctx.getBean("injectCollection"); instance.displayInfo(); } public void setList(List list) { this.list = list; } public void setSet(Set set) { this.set = set; } public void setMap(Map <String, Object> map) { this.map = map; } public void setProps(Properties props) { this.props = props; } public void displayInfo() { // display the Map System.out.println("Map contents:\n"); for (Map.Entry<String, Object> entry: map.entrySet()) { System.out.println("Key: " + entry.getKey() + " - Value: " + entry.getValue()); } // display the properties System.out.println("\nProperties contents:\n"); for (Map.Entry<Object, Object> entry: props.entrySet()) { System.out.println("Key: " + entry.getKey() + " - Value: " + entry.getValue()); } // display the set System.out.println("\nSet contents:\n"); for (Object obj: set) { System.out.println("Value: " + obj); } // display the list System.out.println("\nList contents:\n"); for (Object obj: list) { System.out.println("Value: " + obj); } } }
<bean id="oracle" name="wiseworm" class="com.apress.prospring3.ch4.BookwormOracle"/> <bean id="injectCollection" class="com.apress.prospring3.ch4.xml.CollectionInjection"> <property name="map"> <map> <entry key="someValue"> <value>Hello World!</value> </entry> <entry key="someBean"> <ref local="oracle"/> </entry> </map> </property> <property name="props"> <props> <prop key="firstName">Clarence</prop> <prop key="secondName">Ho</prop> </props> </property> <property name="set"> <set> <value>Hello World!</value> <ref local="oracle"/> </set> </property> <property name="list"> <list> <value>Hello World!</value> <ref local="oracle"/> </list> </property> </bean>////////////////////////////////////////////////////////////////////////////////////////////////////////////
<util:map id="map" map-class="java.util.HashMap"> <entry key="someValue"> <value>Hello World!</value> </entry> <entry key="someBean"> <ref bean="oracle"/> </entry> </util:map> <util:properties id="props"> <prop key="firstName">Clarence</prop> <prop key="secondName">Ho</prop> </util:properties> <util:set id="set"> <value>Hello World!</value> <ref bean="oracle"/> </util:set> <util:list id="list"> <value>Hello World!</value> <ref bean="oracle"/> </util:list>
@Service("injectCollection") public class CollectionInjection { @Resource(name="map") private Map<String, Object> map; @Resource(name="props") private Properties props; @Resource(name="set") private Set set; @Resource(name="list") private List list; // Other codes omitted }11.Bean Scopes
Singleton:The default singleton scope.
Prototype:A new instance will be created by Spring when requested by application.
Request:For web application use. When using Spring MVC for web application,
beans with request scope will be instantiated for every HTTP request and then
destroyed when the request is completed.
Session:For web application use. When using Spring MVC for web applications,
beans with session scope will be instantiated for every HTTP session and then
destroyed when the session is over.
Global session:For portlet-based web applications. The global session scope beans
can be shared among all portlets withinthe same Spring MVC–powered portal
application.
Thread: A new bean instance will be created by Spring when requested by a new
thread, while for the same thread, the same bean instance will be returned. Note
that this scope is not registered by default.
Custom:Custom bean scope that can be created by implementing the interface
org.springframework.beans.factory.config.Scopeand registering the custom
scope in Spring’s configuration (for XML, use the class org.springframework.beans
.factory.config.CustomScopeConfigurer).
新书推荐《JavaEE开发的颠覆者: Spring Boot实战》,涵盖Spring 4.x、Spring MVC 4.x、Spring Boot企业开发实战。
京东地址:http://item.jd.com/11894632.html
当当地址:http://product.dangdang.com/23926195.html
亚马逊地址:http://www.amazon.cn/图书/dp/B01D5ZBFUK/ref=zg_bsnr_663834051_6
淘宝地址:https://item.taobao.com/item.htm?id=528426235744&ns=1&abbucket=8#detail
或自己在京东、淘宝、亚马逊、当当、互动出版社搜索自选。
相关推荐
spring学习1-29集无拖拽
以下是对"Spring学习资料大全"的详细解析: 1. **Spring框架基础**: - **依赖注入(Dependency Injection,DI)**:Spring的核心特性之一,它允许开发者在运行时通过XML配置或注解方式来管理对象间的依赖关系,...
本资料“Spring学习笔记&源码”是基于网易云课堂黑马程序员的Spring四天精通课程,旨在帮助学习者深入理解和实践Spring框架。 笔记部分可能会涵盖以下内容: 1. **Spring概述**:介绍Spring框架的历史、特点和主要...
本资源集合围绕"spring学习.zip",提供了多本深入讲解Spring及其相关技术的电子书籍,旨在帮助读者深入理解和掌握Spring生态。 1. **《深入实践Spring Boot.陈韶健.pdf》**:这本书详细介绍了Spring Boot,它是...
《SpringCloud视频学习》 SpringCloud作为微服务架构的重要实现框架,深受广大开发者的喜爱。本资源包含了两部关于SpringCloud的视频教程,由尚硅谷出品,内容详实且易于理解,是学习SpringCloud的理想资料。 一、...
Springcloud学习笔记.md,Springcloud学习笔记.md,Springcloud学习笔记.md,Springcloud学习笔记.md,Springcloud学习笔记.md,Springcloud学习笔记.md,Springcloud学习笔记.md,Springcloud学习笔记.md,Spring...
由于提供的文件内容中存在大量重复的网址信息,并没有实际的教学内容或者相关知识点,我将从标题“spring 学习”出发,结合描述“通过搭建基本的工程,从中学习spring的原理”来详细阐述Spring框架的相关知识点。...
本学习提纲旨在为初学者提供一份详尽的Spring 2.0学习指南,帮助他们系统地掌握这个框架的核心概念和技术。 一、Spring概述 1. Spring框架介绍:理解Spring的起源,目标及主要功能,包括简化Java EE开发、提供容器...
spring学习笔记
为了深入学习Spring,你可以参考官方文档、在线教程、书籍,如《Spring in Action》等,以及参与开源社区,如Stack Overflow、GitHub等,积累实战经验。 总的来说,Spring框架是Java开发的强大工具,理解和掌握其...
spring系统学习,解读spring,源码解读 spring系统学习,解读spring,源码解读 spring系统学习,解读spring,源码解读
Spring学习思维导图Spring学习思维导图Spring学习思维导图Spring学习思维导图Spring学习思维导图Spring学习思维导图Spring学习思维导图Spring学习思维导图Spring学习思维导图Spring学习思维导图Spring学习思维导图...
Spring学习资料文档合集,包含 spring2.0-reference_RC2.1_zh_cn spring_reference_inchinese_m2 SpringGuide Spring基础教程 spring框架,技术详解及使用指导
从"Spring_day1"开始,可能涵盖了Spring的基础概念、环境搭建和基本配置。"Spring_day2"可能涉及了依赖注入和AOP的深入讲解。"Spring_day3"则可能讲解了Spring MVC、Spring Boot或Spring Data等内容。 为了充分利用...
Spring Cloud 学习笔记 本笔记主要介绍了从单体架构到微服务架构的演变过程,以及 Spring Cloud 中的微服务架构搭建。下面是本笔记的详细知识点总结: 一、单体架构 单体架构是指整个系统只有一个工程,打包往往...
这份"Spring学习笔记+学习源码.zip"资源包含了深入学习Spring及其相关技术的知识点,以及实践代码,对提升Spring技能将大有裨益。 首先,我们来详细讨论Spring框架的主要组件和功能: 1. **依赖注入(Dependency ...
学习spring资源书籍,第三版讲解的很全面,包括springmvc的整合
SpringCloud学习手册是一个针对微服务架构的资源包,主要涵盖了SpringCloud的相关知识,适用于初学者。SpringCloud作为Java领域中的主流微服务框架,为开发者提供了构建分布式系统所需的工具和服务发现、配置管理、...
这个压缩包文件集合提供了丰富的学习资源,帮助初学者深入了解和掌握Spring框架。让我们逐一解析这些资源: 首先,"spring2.0-reference_final_zh_cn.chm" 是Spring 2.0的中文参考手册。这个手册详细阐述了Spring ...
Spring学习笔记( spring视频笔记)