Spring日志打印配置
pop.xml文件
| |
| |
| |
| |
| |
| |
| |
| <dependency> |
| <groupId>org.apache.logging.log4j</groupId> |
| <artifactId>log4j-slf4j-impl</artifactId> |
| <version>2.14.0</version> |
| <scope>test</scope> |
| </dependency> |
在resources目录下准备log4j2.xml的配置文件
| <?xml version="1.0" encoding="UTF-8"?> |
| <Configuration status="DEBUG"> |
| <Appenders> |
| <Console name="Console" target="SYSTEM_OUT"> |
| <PatternLayout pattern="%d{YYYY-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n" /> |
| </Console> |
| </Appenders> |
| <Loggers> |
| <Root level="debug"> |
| <AppenderRef ref="Console" /> |
| </Root> |
| </Loggers> |
| </Configuration> |
spring5关于测试工具的支持
整合junit4依赖的jar
| |
| <dependency> |
| <groupId>junit</groupId> |
| <artifactId>junit</artifactId> |
| <version>4.13.1</version> |
| <scope>test</scope> |
| </dependency> |
| |
| <dependency> |
| <groupId>org.springframework</groupId> |
| <artifactId>spring-test</artifactId> |
| <version>5.3.5</version> |
| <scope>test</scope> |
| </dependency> |
测试代码,方法1
| package com.msb.test; |
| import com.msb.config.SpringConfig; |
| import com.msb.service.AccountService; |
| import org.junit.Test; |
| import org.junit.runner.RunWith; |
| import org.springframework.beans.factory.annotation.Autowired; |
| import org.springframework.context.ApplicationContext; |
| import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
| import org.springframework.context.support.ClassPathXmlApplicationContext; |
| import org.springframework.lang.Nullable; |
| import org.springframework.test.context.ContextConfiguration; |
| import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
| |
| |
| |
| |
| @RunWith(SpringJUnit4ClassRunner.class) |
| @ContextConfiguration("classpath:applicationContext.xml") |
| public class Test2 { |
| @Autowired |
| private AccountService accountService; |
| @Test() |
| public void testTransaction(){ |
| int rows = accountService.transMoney(1, 2, 100); |
| System.out.println(rows); |
| } |
| } |
使用util5的包
| |
| <dependency> |
| <groupId>org.junit.jupiter</groupId> |
| <artifactId>junit-jupiter-api</artifactId> |
| <version>5.7.0</version> |
| <scope>test</scope> |
| </dependency> |
测试方法
| import com.msb.service.AccountService; |
| import org.junit.jupiter.api.Test; |
| import org.springframework.beans.factory.annotation.Autowired; |
| import org.springframework.context.ApplicationContext; |
| import org.springframework.context.annotation.aspectj.EnableSpringConfigured; |
| import org.springframework.context.support.ClassPathXmlApplicationContext; |
| import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; |
| |
| @SpringJUnitConfig(locations = "classpath:Application.xml") |
| public class test { |
| @Autowired |
| private AccountService accountService; |
| @Test |
| public void test1(){ |
| |
| |
| int rows = accountService.transMoney(1, 2, 100); |
| System.out.println(rows); |
| } |
| } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!