H5W3
当前位置:H5W3 > 问答 > 正文

springboot中使用jpa报错?

下面是报的错:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘productCategoryRepository’ defined in com.wechat.selectfood.dao.ProductCategoryRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean ‘jpaMappingContext’ while setting bean property ‘mappingContext’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘jpaMappingContext’: 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]

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘jpaMappingContext’: 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]
我的代码如下:

    <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

ProductCategory类:

package com.wechat.selectfood.dateObject;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class ProductCategory {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer categoryId;
private String categoryName;
private Integer categoryType;
public ProductCategory() {
}
public Integer getCategoryId() {
return categoryId;
}
public void setCategoryId(Integer categoryId) {
this.categoryId = categoryId;
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
public Integer getCategoryType() {
return categoryType;
}
public void setCategoryType(Integer categoryType) {
this.categoryType = categoryType;
}
}

ProductCategoryRepository接口

package com.wechat.selectfood.dao;
import com.wechat.selectfood.dateObject.ProductCategory;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ProductCategoryRepository extends JpaRepository<ProductCategory,Integer>{
}

回答

遇到这种情况,大概率都是少了注解,因为我也在学这个
还有,我们好像看的是同一部教学视频,因为你这段代码我上上周写过,回去给你翻翻

未经允许不得转载:H5W3 » springboot中使用jpa报错?

赞 (0)

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址