SpringBoot集成mySql
启动项目报如下错误:
解决方案:在pom.xml文件中只引用了mybatis-spring-boot-starter,少引用了jar包mysql-connector-java
单元测试
1、单元测试中不识别@Autowired,
解决方案:在单元测试类上增加注解@RunWith(SpringRunner.class)
@SpringBootTest
单元测试类:
package com.example;
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;
import com.example.domain.User;
import com.example.service.UserMessageService;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringTest {
@Autowired
public UserMessageService userMessageService;
@Test
public void test() {
User u=new User();
u.setId("1");
u.setUserName("zhangsan");
u.setPassWord("1");
u.setAge("18");
u.setSex("1");
userMessageService.insert(u);
}
}