我在使用Spring Boot和Hibernate进行基本项目中的配置时遇到问题。 控制台向我显示:需要找不到名为'entityManagerFactory'的bean。 我从这里尝试了许多技巧,但没有一个对我有用。 有人可以帮我吗?
这是我对pom.xml的依赖:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.4.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.4.4.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.1.10.RELEASE</version>
</dependency>
</dependencies>
这是我的MainController:
@SpringBootApplication
@EnableJpaRepositories
public class MainController {
public static void main(String[] args) {
SpringApplication.run(MainController.class, args);
}
}
这是我的UserController:
@RestController
public class UserController {
@Autowired
private UserDao userDao;
@CrossOrigin(origins = "http://localhost:3000")
@PostMapping("/tbs/login")
public boolean logIn(@RequestBody(required = false) User user) {
Boolean userExist = false;
User user = userDao.checkIfExistByEmail(user.getEmail());
return user != null ? true : false ;
}
}
这是我的UserDao:
@Repository
public interface UserDao extends JpaRepository<User, Long> {
@Query("SELECT u FROM user WHERE u.email = ?1")
User checkIfExistByEmail(String email);
}