XML Constructer injection
<?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 name="myCustomerRepository"
class="com.pluralsight.repository.HibernateCustomerRepositoryImpl" />
<bean name="customerService" class="com.pluralsight.service.CustomerServiceImpl" >
<!-- <property name="customerRepository" ref="myCustomerRepository" /> -->
<constructor-arg index="0" ref="myCustomerRepository"></constructor-arg>
</bean>
</beans>
package com.pluralsight.service;
import java.util.List;
import com.pluralsight.model.Customer;
import com.pluralsight.repository.CustomerRepository;
import com.pluralsight.repository.HibernateCustomerRepositoryImpl;
public class CustomerServiceImpl implements CustomerService {
private CustomerRepository customerRepository;
public CustomerServiceImpl() {
}
public CustomerServiceImpl(CustomerRepository repository){
this.customerRepository = repository;
}
/* (non-Javadoc)
* @see com.pluralsight.service.CustomerService#findAll()
*/
@Override
public List<Customer> findAll(){
return customerRepository.findAll();
}
public void setCustomerRepository(CustomerRepository customerRepository) {
this.customerRepository = customerRepository;
}
}