当前位置: 首页 > 知识库问答 >
问题:

spring boot,没有找到依赖项的合格bean类型:需要至少1个bean可以作为此依赖项的自动候选项

符功
2023-03-14
@Controller
@EnableAutoConfiguration
public class ControllerShowInfo 
{
    @RequestMapping("/")
    public String rawPage()
    {
        return "rawPage";
    }

    @Autowired
    stockreviewsRepositoryDao repository;

    @RequestMapping("/getBaseInfo")
    @ResponseBody
    public JSONArray getReviewsInfo()
    {
        JSONArray jsonArray = new JSONArray();
        for (stockreviewsBean reviewBean : repository.findAll()) 
        {
            jsonArray.put(reviewBean);
            System.out.println(reviewBean.getTitle());
        }
        return jsonArray;
    }
    public static void main(String[] args) throws Exception 
    {
        SpringApplication.run(ControllerShowInfo.class, args);
    }
}
public interface stockreviewsRepositoryDao extends CrudRepository<stockreviewsBean,String> 
{
}
@SpringBootApplication
public class Application 
{
    public static void main(String[] args) throws Exception 
    {
        SpringApplication.run(Application.class, args);
    }
}
@Component
public class DataInitialization implements CommandLineRunner{

    @Autowired
    stockreviewsRepositoryDao repository;

    @Override
    public void run(String... args) throws Exception 
    {
        System.out.println("-------------------------------");
        int count=0;
        for (stockreviewsBean reviewBean : repository.findAll()) 
        {
            count++;
            System.out.println(reviewBean.getTitle());
        }
        System.out.println(count);
    }
}

效果很好。我真的很困惑。

共有1个答案

温翔宇
2023-03-14

你试过注解吗

StockReviewsRepositorYDAO使用@repository

而且

 类似资料: