我用spring-data-jpa用spring-boot(v2.0.0.RELEASE),只是写在MySQL凝乳演示,但它如下发生运行时异常,源代码如下:
源代码
User.java
@Entity
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private Integer id;
private String username;
private String password;
...getter&setter
}
Run Code Online (Sandbox Code Playgroud)
UserRepository.java
public interface UserRepository extends JpaRepository<User, Integer> {
}
Run Code Online (Sandbox Code Playgroud)
UserServiceTest.java
@RunWith(SpringRunner.class)
@SpringBootTest
public class UserServiceTest {
@Autowired
private UserRepository userRepository;
@Test
public void getUserById() throws Exception{
userRepository.getOne(1);
}
}
Run Code Online (Sandbox Code Playgroud)
application.yml
spring:
datasource:
username: ***
password: ***
driver-class-name: com.mysql.jdbc.Driver
url: ********
thymeleaf:
cache: false
jpa:
show-sql: true
hibernate: …Run Code Online (Sandbox Code Playgroud)