SSM-Spring-Spring装配Bean-通过注解装配Bean-装载带有参数构造方法类

SSM-Spring-Spring装配Bean-通过注解装配Bean-装载带有参数构造方法类

​ 对于一些带参数的构造方法,允许通过注解进行注入:

@Component
public class RoleController2{
    
    
    private RoleService roleSercice=null;
    public RoleController2( @Autowired RoleService roleService){
    
    
        this.roleSercice=roleService;
    }
}

通过在构造形参旁边添加注解即可

猜你喜欢

转载自blog.csdn.net/weixin_43958223/article/details/115085685