今日学习记录 下
- springboot项目内部配置文件加载顺序
- 整合junit
springboot项目内部配置文件加载顺序
1. 最低优先级的 resources文件夹下的application.properties
学习配置优先级阵亡。简要记录。config目录下的文件优先级,高于项目根目录的。
2. 外部的加载顺序
一个官方文档:docs.spring.io/spring-boot…
整合junit
pom中增加
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
test包下新建UserServiceTest
package config;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ConfigApplication.class)
public class UserServiceTest {
@Autowired
private UserService userService;
@Test
public void testAdd(){
userService.add();
}
}
java包下增加一个类
package config;
import org.springframework.stereotype.Service;
@Service
public class UserService {
public void add(){
System.out.println("add,,,,,");
}
}
- 注意添加注解
- 注意注解的包路径
- SpringBootTest填入启动类的class
- 左侧开始按钮,点击开始测试