Spring Configuration Using XML - 章节
用XML配置是:
第一种方法
更简单的
关注点分离
applicationContext.xml
Name doesn't matter
Spring Context sort of a HashMap
Can simply be a registry
XML configuration begins with this file
Namespaces aid in configuration/validation
名称空间
<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">
copy project
XML Declaration
Beans
Essentially classes
Replaces keyword new
Define class, use interface
Add Bean
Setter Injection
Constructor Injection
Guaranteed contract
Constructor defined
Used together
Index-based
Autowire
Spring automatically wires beans
byType
byName
constructor
no
byType
byName
总结:
applicationContext.xml
Bean definition
Setter injection
Constructor injection
Autowiring