@Nullable注解
@Nullable
public String add(){
}
public String add(@Nullable String id){
}
@Nullable
private String id;
GenericApplicationContext
spring5容器支持函数式风格
# 实体类
public class User {
}
# 测试方法
@Test
public void testGenericApplicationContext1() {
//1 创建GenericApplicationContext对象
GenericApplicationContext context = new GenericApplicationContext();
//2 调用context的方法对象注册
context.refresh();
context.registerBean(User.class, () -> new User());
//3 获取在spring注册的对象
User user = (User)context.getBean("com.atguigu.spring5.test.User");
System.out.println(user);
}
# 控制台
org.example.demo10.test.User@55182842
# 实体类
public class User {
}
# 测试方法
@Test
public void testGenericApplicationContext2() {
//1 创建GenericApplicationContext对象
GenericApplicationContext context = new GenericApplicationContext();
//2 调用context的方法对象注册
context.refresh();
context.registerBean("user1",User.class,() -> new User());
//3 获取在spring注册的对象
User user = (User)context.getBean("user1"); // 由于这种方式获取bean,不是根据类名小写,而是在第2步指定
System.out.println(user);
}
# 控制台
org.example.demo10.test.User@55182842