请稍等 ...
×

采纳答案成功!

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

repository 飘红


package com.imooc.repository;

import com.imooc.dataobject.ProductCategory;
import com.imooc.repository.ProductCategoryRepository;
import com.imooc.sell.SellApplication;
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 static org.junit.Assert.*;

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

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

中的private ProductCategoryRepository repository; repository 红色,显示找不到bean autowire

我的pom版本直接用的git上的,实在不知道哪出错了

正在回答 回答被采纳积分+3

3回答

慕粉18821273958 2018-11-20 13:38:53

将@Springbootapplication的项目启动类放在项目根目录(com.imooc)下试试,然后就可以去掉 (classes = SellApplication.class)了。

1 回复 有任何疑惑可以回复我~
  • 楼上正解!
    回复 有任何疑惑可以回复我~ 2019-04-21 22:27:11
廖师兄 2019-04-05 09:30:49

不需要加@Repository的。你运行我的源码看看。

0 回复 有任何疑惑可以回复我~
提问者 IIllIIllIIll 2018-08-10 17:17:46
package com.imooc.repository;

import com.imooc.dataobject.ProductCategory;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface ProductCategoryRepository extends JpaRepository<ProductCategory, Integer> {

}

这是我的Dao


0 回复 有任何疑惑可以回复我~
  • 同学你好,请问你这个是怎么解决的,可以请教下吗,我和你一样的问题,谢谢
    回复 有任何疑惑可以回复我~ 2019-04-04 14:40:13
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

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

帮助反馈 APP下载

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

公众号

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