1.整个Sping5框架的代码基于Java8,运行时兼容java9,许多不建议使用的类和方法在代码库中删除
2.Sping5 框架自带了通用的日志封装
(1)Sping5移除了Log4jCongfigLister,官方建议使用Log4j2版本
(2)Sping5框架整个Log4j2
第一步引入jar包:
第二部创建log4j2配置文件 名字叫:log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--日志级别以及优先级排序: OFF > FATAL > ERROR > WARN > INFO > DEBUG > TRACE > ALL -->
<!--Configuration后面的status用于设置log4j2自身内部的信息输出,可以不设置,当设置成trace时,可以看到log4j2内部各种详细输出-->
<configuration status="INFO">
<!--先定义所有的appender-->
<appenders>
<!--输出日志信息到控制台-->
<console name="Console" target="SYSTEM_OUT">
<!--控制日志输出的格式-->
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</console>
</appenders>
<!--然后定义logger,只有定义了logger并引入的appender,appender才会生效-->
<!--root:用于指定项目的根日志,如果没有单独指定Logger,则会使用root作为默认的日志输出-->
<loggers>
<root level="info">
<appender-ref ref="Console"/>
</root>
</loggers>
</configuration>
测试:
public class UserLog {
private static final Logger log= LoggerFactory.getLogger(UserLog.class);
public static void main(String[] args) {
log.info("hello");
log.warn("hello warn");
}
}
3、Spring5 框架核心容器支持@Nullable 注解
(1)@Nullable 注解可以使用在方法上面,属性上面,参数上面,表示方法返回可以为空,属性值可以 为空,参数值可以为空
(2)注解用在方法上面,方法返回值可以为空
(3)注解使用在方法的参数里面,表示方法的参数可以为空
(4)注解使用在属性上面,属性值可以为空
4、Spring5 核心容器支持函数式风格 GenericApplicationContext
//函数式风格创建对象,交给 spring 进行管理
@Test
void test2() {
//创建GenericApplicationContext对象
GenericApplicationContext context=new GenericApplicationContext();
//调用context注册
context.refresh();
context.registerBean("user1",UserLog.class,()->new UserLog());
//获取在Sping里注册的对象
Object user = context.getBean("user1");
System.out.println(user);
}
5、Spring5 支持整合 JUnit5
(1)整合 JUnit4 第一步 引入 Spring 相关针对测试依赖
@RunWith(SpringJUnit4ClassRunner.class)//单元测试框架
@ContextConfiguration("classpath:mysqlbean.xml")//加载配置文件
public class JTest {
@Autowired
private UserService userService;
@Test
public void test(){
userService.accountMoney("sunchao","xiaoming",100);
}
}
跟之前使用的:
@Test
void test2() {
//创建GenericApplicationContext对象
GenericApplicationContext context=new GenericApplicationContext();
//调用context注册
context.refresh();
context.registerBean("user1",UserLog.class,()->new UserLog());
//获取在Sping里注册的对象
Object user = context.getBean("user1");
System.out.println(user);
}
(2)Spring5 整合 JUnit5
第一步 引入 JUnit5 的 jar 包
@ExtendWith(SpringExtension.class)
@ContextConfiguration("classpath:bean1.xml")
public class JTest5 {
@Autowired
private UserService userService;
@Test
public void test1() {
userService.accountMoney();
}
}
(3)使用一个复合注解替代上面两个注解完成整合
@SpringJUnitConfig(locations = "classpath:bean1.xml")
public class JTest5 {
@Autowired
private UserService userService;
@Test
public void test1() {
userService.accountMoney();
}
}