h2 web consloe是一个数据库GUI管理应用,就和phpMyAdmin类似。程序运行时,会自动启动h2 web consloe。当然你也可以进行如下的配置。
spring.h2.console.settings.web-allow-others=true,进行该配置后,h2 web consloe就可以在远程访问了。否则只能在本机访问。
spring.h2.console.path=/h2-console,进行该配置,你就可以通过YOUR_URL/h2-console访问h2 web consloe。YOUR_URL是你程序的访问URl。
spring.h2.console.enabled=true,进行该配置,程序开启时就会启动h2 web consloe。当然这是默认的,如果你不想在启动程序时启动h2 web consloe,那么就设置为false。
UserRepositoryTest
@SpringBootTest
@RunWith(SpringRunner.class)
@Slf4j
public class UserRepositoryTest {
@Autowired
private UserRepository userRepository;
@Test
public void saveTest() throws Exception {
User user = new User();
user.setName("郑龙飞");
user.setUrl("http://merryyou.cn");
User result = userRepository.save(user);
log.info(result.toString());
Assert.assertNotNull(user.getId());
}
@Test
public void findOneTest() throws Exception{
User user = userRepository.findOne(1l);
log.info(user.toString());
Assert.assertNotNull(user);
Assert.assertTrue(1l==user.getId());
}
}