ZYZ

SpringBoot学习路上遇到的问题

有 N 人看过

数据库无法连接

  1. 配置文件异常 例如:

    1
    2
    3
    4
    5
    6
    7
    spring:
    datasource:
    driver-class-name: com.mysql.jdbc.Driver
    Url: jdbc:mysql://:/WXDinner?
    username:
    password:

    但是下方的方式可以使用

    1
    2
    3
    4
    spring.datasource.driver-class-name= com.mysql.cj.jdbc.Driver
    spring.datasource.url=jdbc:mysql://:/WXDinner?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false
    spring.datasource.username=
    spring.datasource.password=
  2. 没装连接用的jar包

SpringBoot测试

例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@RunWith(SpringRunner.class)
@SpringBootTest
public class SampleTest {

@Autowired
private UserMapper userMapper;

@Test
public void testSelect() {
System.out.println(("----- selectAll method test ------"));
List<User> userList = userMapper.selectList(null);
Assert.assertEquals(5, userList.size());
userList.forEach(System.out::println);
}

}

Service错误

未使用注释@Service,若使用serviceimp则应在impl中标注@Service

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

mapper.java与mapper.xml文件名应相同

1
mapper-locations未配置正确