我正在尝试升级我的申请,但我得到了 “一个组件需要找不到类型为'javax.persistence.EntityManagerFactory'的bean。”
我已经尝试了其他问题中给出的解决方案。但是他们都没有为我工作。
**存储库**
@Repository
public interface UserRepository extends JpaRepository< RegistrationModel, Long>
{
}
** Controller.java **
@RestController
@RequestMapping("bibliophile")
public class RegistrationController {
RegistrationController() {
}
@Autowired
UserRepository user;
@RequestMapping(value = "registration", method = RequestMethod.POST)
public String registration( @RequestBody RegistrationModel request) {
// request.getURI();
user.save(request);
return "Hello I am working";
}
}
SpringApplication
@SpringBootApplication
@ComponentScan(value="com.ajtas.bib")
@EnableJpaRepositories(basePackageClasses = UserRepository.class)
public class BibliophilerApplication {
public static void main(String[] args) {
SpringApplication.run(BibliophilerApplication.class, args);
}
}
** Pom.xml **
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.ajtas</groupId>
<artifactId>udemy-spring-tutorial</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>bibliophiler</name>
<description>Bibliophiler</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--<scope>provided</scope>-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
答案 0 :(得分:0)
连同pom.xml中的休眠条目,尝试在Spring Boot application.properties文件中添加休眠连接属性