【问题标题】:Field countRepo in com.abc.serive.MysqlService required a bean of type 'com.abc.repository.ClicksQuickReplyRepository' that could not be foundcom.abc.serive.MysqlService 中的字段 countRepo 需要找不到类型为“com.abc.repository.ClicksQuickReplyRepository”的 bean
【发布时间】:2019-07-20 12:27:03
【问题描述】:
package com.abc.repository.ClicksQuickReplyRepository;

import com.abc.model.ClicksQuickReply;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;

@Repository
public interface ClicksQuickReplyRepository{

    @Query( value = "select notificationTag,count,button_id from fb_sent_messages where page_id=?1 and notificationTag in ?2", nativeQuery=true)
    List<ClicksQuickReply> getClickCount(@Param("pageID") String pageID, @Param("notificationTag")  String notificationTag);
}

MySQL 服务类

package com.abc.serive.MysqlService;

@Service
public class MysqlService {

@Autowired
    private ClicksQuickReplyRepository clicksQuickReplyRepository;

} 

自动装配 ClicksQuickReplyRepository 会导致错误:

Field clicksQuickReplyRepository in com.abc.serive.MysqlService required a bean of type 'com.abc.repository.ClicksQuickReplyRepository' that could not be found.

我尝试了以下尝试修复它:

  1. @EnableJpaRepositories添加到SpringConfiguration类
  2. 已添加@SpringBootApplication(scanBasePackages={"com.abc.repository"})scanBasePackage // 开始导致其他包相同的错误

【问题讨论】:

  • @SpringBootApplication 在什么包中?
  • com.abc 包@Andronicus

标签: java mysql sql spring spring-boot


【解决方案1】:

这可能是由错误的映射引起的,在您的查询中有where page_id=?1 而您的参数名称是pageID。这些应该是平等的。错误的映射导致没有 bean 注入。

【讨论】:

  • 我根据您的建议更改了它:@Query(value = "select notificationTag,count,button_id from fb_sent_messages where page_id=?1 and notificationTag in ?2", nativeQuery=true) List getClickCount (@Param("page_id") String page_id, @Param("notificationTag") String notificationTag);
  • 您确定这些是有效的列名吗?一个是camelCase,另一个是_
  • 是的,也已经交叉检查了
猜你喜欢
  • 1970-01-01
  • 2018-09-22
  • 1970-01-01
  • 2019-12-05
  • 1970-01-01
  • 2020-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多