com.abc.serive.MysqlService中的字段countRepo需要一个类型为'com.abc.repository.ClicksQuickReplyRepository'的bean,

时间:2019-02-26 21:25:57

标签: hibernate spring-boot jpa autowired

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 //开始导致其他程序包出现相同的错误

1 个答案:

答案 0 :(得分:1)

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