尝试使用 Spring JPA 实现物化视图时出现问题

问题描述 投票:0回答:1

我正在尝试按照多个在线指南在我的项目中使用 Spring JPA 实现物化视图。物化视图是使用 Liquibase 创建的,如下所示。下面还显示了视图的实体代码以及相应的存储库和服务类代码。

CREATE MATERIALIZED VIEW IF NOT EXISTS summary
AS
SELECT personal_details.id_no, address.address from personal_details
JOIN address
ON personal_details.id_no = address.id_no
ORDER BY personal_details.id_no;
@Entity
@Immutable
@Getter
@Table(name = "summary")
public class Summary {
    @Id
    @Column(name = "id_no")
    private String idNo;

    @Column(name = "address")
    private String address;
}
@NoRepositoryBean
public interface ReadOnlyRepository<T, ID> extends Repository<T, ID> {

    List<T> findAll();

    List<T> findAll(Sort sort);

    Page<T> findAll(Pageable pageable);

    Optional<T> findById(ID id);

    long count();
}
public interface SummaryRepository extends ReadOnlyRepository<Summary, String> {
    List<Summary> findByidNo(String idNo);
}
@Service
public class SummaryServiceImpl implements SummaryService {
    @Autowired
    private SummaryRepository summaryRepository;

    @Override
    public List<Summary> test() {
        return summaryRepository.findAll();
    }
}

但是,我在尝试运行该程序时总是遇到错误。我在这里做错了什么?

Description:

Field summaryRepository in services.impl.SummaryServiceImpl required a bean of type 'repositories.SummaryRepository' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'repositories.SummaryRepository' in your configuration.


Process finished with exit code 1
java spring-boot view spring-data-jpa materialized-views
1个回答
0
投票

@NoRepositoryBeanjavadoc

用于排除存储库接口被拾取的注释,从而避免创建实例。

© www.soinside.com 2019 - 2024. All rights reserved.