【发布时间】:2020-09-03 15:41:05
【问题描述】:
我的应用程序有两个数据库,因此我将实体放在两个单独的文件夹中以简化操作。
Entity/
Local/
User.php
Foo.php
Remote/
Bar.php
但我在连接时遇到了一个我不明白的错误 500
[2020-09-03 17:10:58] request.CRITICAL:
Uncaught PHP Exception Doctrine\Persistence\Mapping\MappingException: "The class 'App\Entity\Local\User' was not found in the chain configured namespaces " at /www/myapp/vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/MappingException.php line 23 {"exception":"[object] (Doctrine\\Persistence\\Mapping\\MappingException(code: 0): The class 'App\\Entity\\Local\\User' was not found in the chain configured namespaces at /www/myapp/vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/MappingException.php:23)"} []
这是我的学说.yml 配置
doctrine:
dbal:
default_connection: local
connections:
local:
url: '%env(resolve:DATABASE_URL)%'
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
remote:
url: '%env(resolve:DATABASE_URL_MS)%'
charset: 'UTF-8'
wrapper_class: App\Connections\ConnectionRemote
mapping_types:
timestamp: string
xml: string
schema_filter: $sales$
orm:
auto_generate_proxy_classes: '%kernel.debug%'
default_entity_manager: local
entity_managers:
local:
connection: local
mappings:
local:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/Local'
prefix: 'App\Entity\Local'
alias: local
AnotherBundle: ~
remote:
connection: remote
mappings:
remote:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/Remote'
prefix: 'App\Entity\Remote'
alias: remote
即使是陌生人,如果我刷新我的页面,我连接良好并且错误不会再次出现...
更疯狂的是,它在开发模式下运行得非常好
【问题讨论】:
-
可能会尝试“bin/console cache:clear” 有时也需要composer dump-autoload,尽管我认为在这种情况下不需要它。如果两者都没有帮助,那么我怀疑是 AnotherBundle 导致了问题。
-
正如@Cerad 所建议的,您必须运行
composer dump-autoload命令(然后是bin/console cache:clear)来更新命名空间映射。 -
谢谢,但不,这些命令没有帮助。问题一直存在。
-
只是为了好玩,尝试“扩展”AnotherBundle 到各种单独的参数中。我知道像 dir: '%kernel.project_dir%/vendor/another-bundle ...' 这样的东西至少可以说有点尴尬,但您至少应该将其排除为问题的可能根源。您还可以通过实际删除 var/cache 目录来尝试“硬缓存清除”。如果您仍然遇到问题,请考虑创建一个新项目,然后仅添加代码以重现该问题。可能发生了其他事情。
-
即使我删除了第二个捆绑包,也不会出现问题。但我设法隔离了一点问题的根源;看起来它不是注入 onSecurityInteractiveLogin 的正确 ORM(仅用于更新用户上次登录日期时间)