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;
}
Autowiring ClicksQuickReplyRepository 会导致错误:
Field clicksQuickReplyRepository in com.abc.serive.MysqlService required a bean of type 'com.abc.repository.ClicksQuickReplyRepository' that could not be found.
我尝试了以下方法来修复它:
- 将
@EnableJpaRepositories
添加到SpringConfiguration类 - 添加了
@SpringBootApplication(scanBasePackages={"com.abc.repository"})
即scanBasePackage
//开始导致其他包出现相同的错误
最佳答案
这可能是由于错误映射造成的,您的查询中存在 where page_id=?1
,而您的参数名称是 pageID
。这些应该是平等的。错误的映射导致没有bean注入(inject)。
关于java - com.abc.serive.MysqlService 中的字段 countRepo 需要类型为 'com.abc.repository.ClicksQuickReplyRepository' 的 bean,但无法找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54894356/