springboot中本地测试相关
本地测试
- springboot中使用junit测试,必须引入相关的依赖
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.3.3.RELEASE</version>
<scope>test</scope>
</dependency>
- 在src/test/java中创建测试类
BasicTest.class
@RunWith(SpringJUnit4ClassRunner.class)
//等价于@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class BasicTest {
}
UserServiceTest.class
public class UserServiceTest extends BasicTest {
@Autowired
private UserService userService;
@Test
public void testfindAll(){
userService.findAll().forEach(user-> System.out.println(user));
}
}
开启jsp页面热部署
热部署:再不需要重新启动服务器的情况下,将jsp页面的修改立即生效的过程。
注意:在springboot中,默认的jsp页面的部署方式是生产模式部署(修改之后需要重新启动服务器才能生效)。
server:
port: 8989
servlet:
context-path: /test
jsp:
init-parameters:
development:true