参考老师代码,运行测试方法系统报PropertyReferenceException

来源:4-2 买家类目-dao(下)

IT菜鸟123

2018-12-23

异常信息:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Factory method 'requestMappingHandlerAdapter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.format.support.FormattingConversionService]: Factory method 'mvcConversionService' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productCategoryRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property categoryType found for type ProductCategory! Did you mean 'category_type'?

实体:

@Entity
@DynamicUpdate
@Data
public class ProductCategory {
    //类目id
    @Id
    @GeneratedValue
    private Integer category_id;
    //类目名字
    private String category_name;
    //类目编号
    private Integer category_type;
    //创建时间
//    private Date create_time;
    //修改时间
//    private Date update_time;

    public ProductCategory() {
    }

    public ProductCategory(String category_name, Integer category_type) {
        this.category_name = category_name;
        this.category_type = category_type;
    }
}

ProductCategoryRepository接口

public interface ProductCategoryRepository extends JpaRepository<ProductCategory, Integer> {
    List<ProductCategory> findByCategoryTypeIn(List<Integer> categoryTypeList);
}

ProductCategoryRepositoryTest测试类findByCategoryTypeInTest方法

    @Test
    public void findByCategoryTypeInTest() {
        List<Integer> list = Arrays.asList(2,3,4);

        List<ProductCategory> result = repository.findByCategoryTypeIn(list);
        Assert.assertNotEquals(0, result.size());
    }
}
写回答

1回答

廖师兄

2018-12-24

同学,我看你问过类似的问题了。变量的命名不对,category_id,要用驼峰命名,请看源码

0
1
IT菜鸟123
非常感谢!
2018-12-25
共1条回复

Spring Boot双版本(1.5/2.1) 打造企业级微信点餐系统

从0到1开发中小型企业级Java应用,并学会迭代重构技巧

6410 学习 · 5247 问题

查看课程