Dependency injection assembly annotations based Bean
- Note: is a class, use the annotation name @
- Development: Using annotations replace xml configuration file.
1.@Component取代<bean class="">
@Component("id") 取代 <bean id="" class="">
2.web development, provides annotations derived annotation @Component 3 (function as) a substituted
@Repository: dao layer
@Service: service layer
@Controller: web layer
3. dependency injection, private field is set to a value, may be set to a value setter methods
Normal values: @Value ( "")
Reference values:
Embodiment 1: [type] according injection
@Autowired
Embodiment 2: 1 injection according to [Name]
@Autowired
@Qualifier ( "name")
Embodiment 3: 2 according to [Name] injection
@Resource ( "name")
4. Life Cycle
Initialization: @PostConstruct
Destruction: @PreDestroy
5. Scope
@Scope ( "prototype") cases of
NOTE Using the premise, add a namespace, class notes let you scan a spring