当我启动我的springboot应用程序时,我得到一个错误
field materialRequestRepo in com.sql.csse.ControllerManager.MaterialRequestController required a bean named 'entityManagerFactory' that could not be found.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.4.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.3.Final</version>
</dependency>
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
对于这个问题,正如您在这里看到的,他们要求添加与我之前删除的相同的依赖项。
这里可能发生了什么问题?
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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.sql.test</groupId>
<artifactId>SpringBoot-sqlTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SpringBoot-sqlTest</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.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-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.11.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.3.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.sql.csse.ControllerManager;
import com.google.gson.Gson;
import com.sql.csse.EntityManager.MaterialRequest;
import com.sql.csse.EntityManager.Order;
import com.sql.csse.EntityManager.Supplier;
import com.sql.csse.RepositoryManager.MaterialRequestRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("/Requests")
public class MaterialRequestController {
@Autowired
MaterialRequestRepo materialRequestRepo;
MaterialRequest materialRequest;
List<MaterialRequest> materialList;
@RequestMapping(method = RequestMethod.POST , value = "/save" , produces = MediaType.APPLICATION_JSON_VALUE)
public List<MaterialRequest> MaterialRequests(@RequestBody String mr){
Gson gson = new Gson();
materialRequest = gson.fromJson(mr, MaterialRequest.class);
materialRequestRepo.save(materialRequest);
return materialRequestRepo.findAll();
}
@RequestMapping(method = RequestMethod.GET , value = "/getall" , produces = MediaType.APPLICATION_JSON_VALUE)
public List<MaterialRequest> getAll(){
return materialRequestRepo.findAll();
}
@RequestMapping(method = RequestMethod.GET , value = "/getallPending" , produces = MediaType.APPLICATION_JSON_VALUE)
public ArrayList<MaterialRequest> getPendingRequests(){
return materialRequestRepo.findpendingRequests();
}
}
MaterialRequest(实体)
package com.sql.csse.EntityManager;
import javax.persistence.*;
@Entity
@Table(name ="material_requests")
public class MaterialRequest {
@Id
@Column(name = "RID")
@GeneratedValue(strategy = GenerationType.AUTO)
private int RID;
@Column(name = "MID")
private int MID;
@Column(name = "material_name")
private String material_name;
@Column(name = "material_quantity")
private double material_quantity;
@Column(name = "requested_date")
private String requested_date;
@Column(name = "order_date")
private String order_date;
@Column(name = "satatus")
private String status;
public MaterialRequest(int MID, String material_name, double material_quantity, String requested_date, String order_date, String status) {
this.MID = MID;
this.material_name = material_name;
this.material_quantity = material_quantity;
this.requested_date = requested_date;
this.order_date = order_date;
this.status = status;
}
public MaterialRequest() {
}
public int getRID() {
return RID;
}
public void setRID(int RID) {
this.RID = RID;
}
public int getMID() {
return MID;
}
public void setMID(int MID) {
this.MID = MID;
}
public String getMaterial_name() {
return material_name;
}
public void setMaterial_name(String material_name) {
this.material_name = material_name;
}
public double getMaterial_quantity() {
return material_quantity;
}
public void setMaterial_quantity(double material_quantity) {
this.material_quantity = material_quantity;
}
public String getRequested_date() {
return requested_date;
}
public void setRequested_date(String requested_date) {
this.requested_date = requested_date;
}
public String getOrder_date() {
return order_date;
}
public void setOrder_date(String order_date) {
this.order_date = order_date;
}
public String getStatus() { return status; }
public void setStatus(String status) { this.status = status; }
}
我复制了您的代码,使用这个pom.xml可以很好地工作:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.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-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
这是我的应用程序。属性
spring.datasource.url=jdbc:mysql://localhost:3306/dto
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
使用spring boot 2.0版本。0.M4我有这个问题:
我正在开发一个Spring Boot应用程序,在启动服务器时遇到了这个错误。我不确定我是否错误地定义了任何注释或遗漏了任何依赖项。如有任何帮助,我们将不胜感激。 主类: LeagueService.java: LeagueRepository.java
我被这个问题缠住了。当我尝试运行我的Spring启动应用程序时,我会收到以下消息: 我正在使用Spring Data JPA,如果我理解正确的话,当我使用例如JpaRepository接口时,entityManager会自动实现到我的项目中。我是否遗漏了什么?即使我使用的是JpaRepository,我是否应该为entityManager定义一个bean?我尝试将其更改为CrudRepositor
我有一个java项目,它将Spring Boot与JPA结合使用,并将Hibernate用于数据库。我正在尝试建立一个访问数据库的微服务。(我不熟悉微服务和Spring Boot)。 以下是主要课程: IGmCircularsDAO. class: GMCircularsDAOImpl。类别: ParentDAO。班 循环服务。班 当我运行这段代码时,我遇到了以下错误,我已经陷入其中一段时间了。
编辑-更新:我根据本教程创建了一个全新的项目,我注意到,在配置pom后,问题是如果我添加 应用程序类的注释。 我是Spring Boot的新手,我已经创建了一个具有持久性的简单工作应用程序,现在我试图添加Spring security jwt,但它不起作用。 以下是我的项目结构: 在为安全性添加依赖项之前,它在持久性方面都工作得很好,现在是这样。我错过了什么?
我正在使用JPA开发一个Spring Boot应用程序,遇到了这个错误。我不确定我是否使用了正确的注释或缺少依赖项。任何帮助都将不胜感激。 这是错误消息 userrepository.java user.java