请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

运行findByCategory_typeInTest测试方法的时候报错

报错信息

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 category found for type ProductCategory!

ProductCategory实体类

package com.imooc.sell.dataobject;

import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
 * 类目
 */
@Entity
@DynamicUpdate
@lombok.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接口

package com.imooc.sell.repository;

import com.imooc.sell.dataobject.ProductCategory;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

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

ProductCategoryRepositoryTest测试类

package com.imooc.sell.repository;

import com.imooc.sell.dataobject.ProductCategory;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.transaction.Transactional;
import java.util.Arrays;
import java.util.List;


@RunWith(SpringRunner.class)
@SpringBootTest
public class ProductCategoryRepositoryTest {
    @Autowired
    private ProductCategoryRepository repository;

    @Test
    public void findOneTest() {
        ProductCategory productCategory = repository.findOne(1);
        System.out.println(productCategory.toString());
    }

    @Test
    @Transactional
    public void saveTest() {
        ProductCategory productCategory = new ProductCategory("女生最爱", 4);
        ProductCategory result = repository.save(productCategory);
        Assert.assertNotNull(result);
    }

    @Test
    public void findByCategory_typeInTest() {
        List<Integer> list = Arrays.asList(2,3,4);
       List<ProductCategory> result= repository.findByCategory_typeIn(list);
        Assert.assertNotEquals(0,result.size());
    }
}

正在回答

1回答

廖师兄 2018-12-22 21:17:30

findByCategory_typeIn 方法名怎么会有下划线呢,需遵循驼峰命名,请参照视频和源码

0 回复 有任何疑惑可以回复我~
  • 提问者 IT菜鸟123 #1
    方法名改完依然报错
    回复 有任何疑惑可以回复我~ 2018-12-23 15:07:11
  • 廖师兄 回复 提问者 IT菜鸟123 #2
    private Integer category_type;  属性名也要改,你看我源码里,都是驼峰
    回复 有任何疑惑可以回复我~ 2018-12-24 21:50:26
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号