首页 新闻 搜索 专区 学院

springboot中使用jpa报错?

0
悬赏园豆:10 [待解决问题]

下面是报的错:
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>{
}
知新小家的主页 知新小家 | 菜鸟二级 | 园豆:205
提问于:2020-06-15 10:37
< >
分享
所有回答(3)
0

要不要加个@Table

随风行云 | 园豆:541 (小虾三级) | 2020-06-15 16:21

在哪里加?

支持(0) 反对(0) 知新小家 | 园豆:205 (菜鸟二级) | 2020-06-15 16:55

我这个是jpa的 不是mybatis,算了,我还是先学学基础吧

支持(0) 反对(0) 知新小家 | 园豆:205 (菜鸟二级) | 2020-06-15 16:57

@知新小家: 就在@Entity下面,@Table(“表名”)

支持(0) 反对(0) 随风行云 | 园豆:541 (小虾三级) | 2020-06-15 17:38

@知新小家: 我知道你的是jpa的,看得出来,

支持(0) 反对(0) 随风行云 | 园豆:541 (小虾三级) | 2020-06-15 17:38

@随风行云: 加了,没有解决,打算从头学一遍

支持(0) 反对(0) 知新小家 | 园豆:205 (菜鸟二级) | 2020-06-17 16:43
0

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

小草上飞飞 | 园豆:177 (初学一级) | 2020-06-16 19:36
0

@ComponentScan了解下这个注解的用处。看看是否bean类没有扫描到。导致的注入失败

Ctrl` | 园豆:2378 (老鸟四级) | 2020-06-17 14:46
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册