我在 Api 平台模块中的存储库的 Symfony 自动配置方面遇到问题。我正在尝试模块化我的 API,并且产品模块 (https://github.com/ControleOnline/api-platform-products) 未读取存储库,导致出现以下错误:
[26-Nov-2023 01:09:41 America/Sao_Paulo] [critical] Uncaught PHP Exception RuntimeException: "The "ControleOnline\Repository\ProductRepository" entity repository implements "Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface", but its service could not be found. Make sure the service exists and is tagged with "doctrine.repository_service"." at /home/control2/sistemas/controleonline/api/vendor/doctrine/doctrine-bundle/Repository/ContainerRepositoryFactory.php line 61
这是我的配置文件:https://github.com/ControleOnline/api-community/tree/master/config
我只需要能够执行模块分离。
检查您的存储库服务是否在 Symfony 服务配置中正确定义。服务定义应包含正确的类并标有“doctrine.repository_service”。检查模块的 services.yaml 文件中的服务定义。
services:
ControleOnline\Repository\ProductRepository:
class: 'ControleOnline\Repository\ProductRepository'
tags: ['doctrine.repository_service']
检查您的模块是否有自己的 Doctrine 配置文件,并确保它正确配置实体管理器和存储库服务。
In your module's config/packages/doctrine.yaml file:
doctrine:
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
重要: 更改配置后,清除 Symfony 缓存:
php bin/console cache:clear
确保清除开发和生产环境。