Spring小总结 发表于 2023-06-26 | 分类于 ---Spring | 静态注入1234567891011121314151617181920@Servicepublic class Teacher { public static Student getStudent(Teacher teacher) { return teacher.student; } @Autowired// 无论属性是否 public/private/省略 【属性不可加 static,@Autowired不可省略】 private Student student; // private Student student; // @Autowired// 无论setter public/private, 无论属性是否 static, 【setter方法不可加 static,@Autowired不可省略】 // public void setStudent(Student student) { this.student = student; } // private static Student student; // @Autowired// 无论构造 public/private, 无论构造上面是否要加@Autowired, 无论属性是否 static // private Teacher(Student student) { this.student = student; } // 总结于 2023-06-26 10:36:22}