1. Annotation-based configuration:
@Component: Basic annotations that identify a component that is managed by Spring
@Respository: Identifying durable layer components
@Service: Identify service layer (business layer) components
@Controller: Identify presentation layer components
Build Interface: Userrepository
Package com.atguigu.spring.beans.annotation.test; Public Interface userrepository { void Save ();}
Build class: Userrepositoryimpl inherits from Interface: Userrepository
Package com.atguigu.spring.beans.annotation.test; Import org.springframework.stereotype.Repository; @Repository (// Identity Persistence layer component Public Classimplements userrepository { publicvoid Save () { System.out.println ("panpan123");} }
Build class: UserService
Package com.atguigu.spring.beans.annotation.test; Import org.springframework.stereotype.Service; @Service // Identify service layer (business layer) components Public class UserService { publicvoid Add () { System.out.println (" panpan456 ");} }
Build class: Usercontroller
Package com.atguigu.spring.beans.annotation.test; Import Org.springframework.stereotype.Controller; @Controller // Identify presentation layer components Public class Usercontroller { publicvoid Test () { System.out.println (" panpan789 ");} }
The above classes are built under the package com.atguigu.spring.beans.annotation.test;
Spring XML configuration file: Beansannotation.xml, with the above four annotations under a Com.atguigu.spring.beans.annotation.test package or sub-package, can be identified by the IOC container
<context:component-scan base-package = "Com.atguigu.spring.beans.annotation.test" > </ Context:component-scan>
Spring Framework Bean Configuration (3): annotation-based configuration, autowired Automatic assembly bean, generic dependency Injection