- 基于Java8,运行时兼容JDK9,许多不建议使用的类和方法在代码中删除
- Spring5已将移除了Log4jConfigListener,官方建议使用Log4j2
- Spring5框架整合Log4j2
- 导入整合Log4j2相关的jar包
- 创建log4j2.xml配置文件
① 设置status的优先级,越往右则优先级别越高,显示的内容越多
② 设置日志输出的格式
- @Nullable注解可用在方法、属性、参数上面,表示方法返回可以为空、属性值可以为空、参数值可以为空
-
函数式风格创建对象,交给spring进行管理
public class TestAccount { @Test public void genericApplicationContextTest() { // 1.创建GenericApplicationContext对象 GenericApplicationContext context = new GenericApplicationContext(); // 2.调用context内的registerBean方法进行对象注册 context.refresh(); context.registerBean("testAccount",TestAccount.class, () -> new TestAccount()); // 3.获取在spring注册的对象 TestAccount testAccount =(TestAccount) context.getBean("testAccount"); System.out.println("testAccount = " + testAccount); } }
- 导入jar包
- 整合Junit4
import org.junit.Test; // 指定单元测试Junit的版本 @RunWith(SpringJUnit4ClassRunner.class) // 指定配置文件 @ContextConfiguration("classpath:bean1.xml") public class Junit4Test { @Autowired private UserService userService; @Test public void test1() { userService.accountMoney(); } } - 整合Junit5
import org.junit.jupiter.api.Test; // 整合Junit5所用的注解 @ExtendWith(SpringExtension.class) // 装载配置文件 @ContextConfiguration("classpath:bean1.xml") public class Junit5Test { @Autowired private UserService userService; @Test public void test1() { userService.accountMoney(); } } - 复合注解@SpringConfig,针对 Junit5
import org.junit.jupiter.api.Test; @SpringJUnitConfig(locations = "classpath:bean1.xml") public class Junit5Test { @Autowired private UserService userService; @Test public void test1() { userService.accountMoney(); } }
- 在创建sping配置文件时,不小心写错了后缀名,导致整个项目中的sping配置文件全部失效了,里面的字都变成了黄色。
- 解决办法:
在File Types -> XML -> 添加:*.xml



