栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Spring新功能

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring新功能

1.自带通用的日志封装log4j2

首先,maven导入依赖坐标


    org.apache.logging.log4j
    log4j-core
    2.14.1



    org.apache.logging.log4j
    log4j-api
    2.14.1




    org.apache.logging.log4j
    log4j-slf4j-impl
    2.14.1
    test



    org.slf4j
    slf4j-api
    1.7.30

其次,创建log4j.xml配置文件





    
    
        
        
            
            
        
    
    
    
    
        
            
        
    

2.核心容器支持@Nullable注解

@Nullable注解可以用在方法上,属性上,参数上,表示可以为空

3.支持函数式风格GenericApplicationContext

//1.创建GenericApplicationContext对象
GenericApplicationContext context = new GenericApplicationContext();
//2.调用Context的方法注册
context.refresh();  //清空
//3.注册
context.registerBean("user",User.class,()->new User());
//4.获取在spring注册的对象
//context.getBean("全限定类名");
context.getBean("user");

4.支持整合Junit5

(1)整合Junit4

首先,导入依赖坐标


    org.springframework
    spring-test
    5.3.9
    test

@RunWith(SpringJunit4ClassRunner.class) :单元测试框架

@ContextConfiguration(“classpath:配置文件”):加载配置文件

(2)整合Junit5

@ExtendWith(SpringExtension.class)

@ContextConfiguration(“classpath:配置文件”):加载配置文件

或者使用复合注解

@SpringJunitConfig(locations="classpath:配置文件")

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/301316.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号