1.注解
-
@configuration (文件配置类,默认单实例) @Configuration(proxyBeanMethods = false)
@Configuration(proxyBeanMethods = true)
-
@Bean(给容器添加组件。以方法名作为组件id。返回类型就是组件类型。返回值,就是组件在容器中的实例) -
@Import({user.class}) 给容器中自动创建出这个类的组件,默认组件名字为 全类名 -
@Conditional 条件装配:满足Conditional指定的条件,则进行组件注入 -
@ImportResource(“classpath:beans.xml”) 导入Spring配置文件 -
@ConfigurationProperties(prefix = “xxxx”) + component 属性绑定
2.Lombak
优点:简化bean开发
@NoArgsConstructor
@Data
@ToString
@EqualsAndHashCode
public class User {
private String name;
private Integer age;
private Pet pet;
public User(String name,Integer age){
this.name = name;
this.age = age;
}
}
================================简化日志开发===================================
@Slf4j
@RestController
public class HelloController {
@RequestMapping("/hello")
public String handle01(@RequestParam("name") String name){
log.info("请求进来了....");
return "Hello, Spring Boot 2!"+"你好:"+name;
}
}
|