XML Configuration
Bryan Hansen
DIRECTOR OF SOFTWARE DEVELOPMENT
@bh5k
First Approach
Simpler
Separation of Concerns
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
Namespaces
<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">
Xml Declaration
<bean
name=“customerService”
class="com.pluralsight.service.CustomerServiceImpl"
autowire=“byName">
<property name="0"
ref="customerRepository" />
</bean>
<bean name=“customerRepository" class=
"com.pluralsight.repository.HibernateCustomerRepositoryImpl"
/>
Beans
Essentially Classes
Replaces keyword new
Define Class, use Interface
Setter Injection
Setter Injection
Constructor Injection
Used together
Better for Existing Code
Constructor Injection
Guaranteed Contract
Constructor Defined
Used together
Index based
Autowire
Spring Automatically Wires Beans
byType
byName
constructor
no
Summary applicationContext.xml
Bean Definition
Setter Injection
Constructor Injection
Auto wiring