Using Spring Boot —— Spring Beans and Dependency Injection

Spring Beans

  @Component @Controller @Service @Respository class specified in the packet scanning @ComponentScan

  @Autowired automatically injected bean, you on the property / constructors / set methods

 

  

package com.example.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DatabaseAccountService implements AccountService {

    private final RiskAssessor riskAssessor;

    @Autowired
    public DatabaseAccountService(RiskAssessor riskAssessor) {
        this.riskAssessor = riskAssessor;
    }

    // ...

}

 

Guess you like

Origin www.cnblogs.com/han6/p/11531955.html