DI IOC annotations and notes
IOC Note:
@Component: for realizing the inversion control ioc, id attribute value for achieving the object defined above;
@Scope: for realizing a single embodiment, multiple cases, request, session configuration and the like;
@Controller: dedicated controller for the annotation layer, to achieve control inversion, attribute value;
@Service: special service for the annotation layer, to achieve control inversion, attribute value;
@Repository: special persistence layer for the annotation, to achieve control inversion, attribute value;
DI Note:
@Resource (name = "userService") - dependency injection
First indexed by name plus type of way; secondly missing name or indeed only be indexed by a type; followed by name and type are omitted, the default name or in accordance retrieval;
@Autowired --- automatic assembly
This annotation to achieve automatic assembly of the injection achieved in accordance with the class if the class of the same name appears, then the annotation mode can not identify which class implements injection, appears abnormal; to avoid if abnormal, can be employed @Qualifier (value = "es") (familiar) implement aid, namely Qualifier can specify the object id;
Example:
user entity classes:
userDao Interface:
userDaoImpl implementation class:
userService business class interface:
userServiceImpl service implementation class:
application-user.xml file:
test:
result: