Reputation: 1973
What happens when we remove the @Repository
annotation in DAO layer in spring?
@Repository
public class EmployeeService {
// ....
@Transactional
public int createEmployee(Employee emp) {
//create Employee
employeeDao.createEmployee(emp);
User user = new User();
// some fileds of employee are used to create a User
user.setEmployeeId(emp.getEmployeeId());
// ....
userDao.createUser(user);
// ...
}
}
Upvotes: 0
Views: 347
Reputation: 3431
You will get:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'employeeService'
@Repository is to create a bean and it indicates that the annotated class is a Repository.
Either you can keep @Repository
or you can add a bean definition in applicationContext.xml
On removing @Repository
and no bean specified in applicationContext.xml
Result: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'employeeService'
Upvotes: 1
Reputation: 694
You will get the following exception if you are not using any annotation or not created respective in the xml configuration. org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'employeeService'
Upvotes: 1