Spring Framework Bean Configuration (3): annotation-based configuration, autowired Automatic assembly bean, generic dependency Injection

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.