Java学习 --- spring5的@Nullable注解与函数式风格

千白莫

关注

阅读 187

2022-03-16

一、Spring5框架核心容器支持@Nullable注解

(1)@Nullable注解可以使用在方法上面,属性上面,参数上面,表示方法返回可以为空,属性值可以为空,参数值可以为空

(2)注解用在方法上面,方法返回值可以为空

二、Spring5核心容器支持函数式风格GenericApplicationContext

@Test
    public void genericApplicationContextTest(){
        //1 创建GenericApplicationContext对象
        GenericApplicationContext context = new GenericApplicationContext();
        //2 调用context的方法对象注册
        context.refresh();
        context.registerBean("user",User.class,() -> new User());
        //3 获取在spring注册的对象
        User user = (User) context.getBean("user");
        System.out.println(user);
    }
}

精彩评论(0)

0 0 举报