repository 飘红
来源:4-1 买家类目-dao(上)
IIllIIllIIll
2018-08-10
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回答
-
慕粉18821273958
2018-11-20
将@Springbootapplication的项目启动类放在项目根目录(com.imooc)下试试,然后就可以去掉 (classes = SellApplication.class)了。
112019-04-21 -
廖师兄
2019-04-05
不需要加@Repository的。你运行我的源码看看。
00 -
IIllIIllIIll
提问者
2018-08-10
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
012019-04-04
相似问题