Symfony2 生产环境:由于在链配置中找不到自定义用户类而导致映射异常



我正在开发一个有点复杂的基于Symfony2.1的应用程序,可以连接到两个不同的数据库(有两个实体管理器,一个连接到Oracle,另一个连接到PostgreSQL)和一个自定义用户类(带有自定义密码编码器)。

我已经设法让它在开发环境中正确运行,但是每当我尝试在生产环境中运行它时,我都会收到下一个错误:

Doctrine\Common\Persistence\Mapping\MappingException:在链配置的命名空间中找不到类'MyFirm\UserManagerBundle\Entity\User'(未捕获的异常)

我在app/config/security.yml中的安全性和编码器:

security:
  encoders:
    MyFirmUserManagerBundleEntityUser:
        id: myfirm_usermanager.password_encoder
  providers:
    user_db:
        entity: 
            class: MyFirmUserManagerBundleEntityUser
            property: username 

app/config/config.yml 中的 doctrine.orm 部分:

doctrine:
  orm:
    auto_generate_proxy_classes: %kernel.debug%
    default_entity_manager: user_config_db 
    entity_managers:
        event_db:
            connection:   event_db
            mappings:
                MyFirmEventManagerBundle: ~
        user_config_db:
            connection:   user_config_db
            mappings:
                MyFirmUserManagerBundle:  ~

最后,这是最终的异常日志:

Exception trace:
 () at C:SF2_projectvendordoctrinecommonlibDoctrineCommonPersistenceMappingMappingException.php:38
 DoctrineCommonPersistenceMappingMappingException::classNotFoundInNamespaces() at C:SF2_projectvendordoctrinecommonlibDoctrineCommonPersistenceMappingDriverMappingDriverChain.php:114
 DoctrineCommonPersistenceMappingDriverMappingDriverChain->loadMetadataForClass() at C:SF2_projectvendordoctrineormlibDoctrineORMMappingClassMetadataFactory.php:112
 DoctrineORMMappingClassMetadataFactory->doLoadMetadata() at C:SF2_projectvendordoctrinecommonlibDoctrineCommonPersistenceMappingAbstractClassMetadataFactory.php:302
 DoctrineCommonPersistenceMappingAbstractClassMetadataFactory->loadMetadata() at C:SF2_projectvendordoctrinecommonlibDoctrineCommonPersistenceMappingAbstractClassMetadataFactory.php:205
 DoctrineCommonPersistenceMappingAbstractClassMetadataFactory->getMetadataFor() at C:SF2_projectvendordoctrineormlibDoctrineORMEntityManager.php:268
 DoctrineORMEntityManager->getClassMetadata() at C:SF2_projectappcacheprodjms_diextradoctrineEntityManager_5075a0dd6e27a.php:345
 EntityManager5075a0dd6e27a_546a8d27f194334ee012bfe64f629947b07e4919__CG__DoctrineORMEntityManager->getClassMetadata() at C:SF2_projectvendorsymfonysymfonysrcSymfonyBridgeDoctrineSecurityUserEntityUserProvider.php:39
 SymfonyBridgeDoctrineSecurityUserEntityUserProvider->__construct() at C:SF2_projectappcacheprodappProdProjectContainer.php:1132
 appProdProjectContainer->getSecurity_User_Provider_Concrete_UserDbService() at C:SF2_projectappbootstrap.php.cache:211
 SymfonyComponentDependencyInjectionContainer->get() at C:SF2_projectappcacheprodappProdProjectContainer.php:1121
 appProdProjectContainer->getSecurity_User_Provider_Concrete_ChainProviderService() at C:SF2_projectappbootstrap.php.cache:211
 SymfonyComponentDependencyInjectionContainer->get() at C:SF2_projectappcacheprodappProdProjectContainer.php:1105
 appProdProjectContainer->getSecurity_Authentication_ManagerService() at C:SF2_projectappbootstrap.php.cache:211
 SymfonyComponentDependencyInjectionContainer->get() at C:SF2_projectappcacheprodappProdProjectContainer.php:552
 appProdProjectContainer->getSecurity_ContextService() at C:SF2_projectappbootstrap.php.cache:211
 SymfonyComponentDependencyInjectionContainer->get() at C:SF2_projectappcacheprodappProdProjectContainer.php:1002
 appProdProjectContainer->getTwigService() at C:SF2_projectappbootstrap.php.cache:211
 SymfonyComponentDependencyInjectionContainer->get() at C:SF2_projectappcacheprodappProdProjectContainer.php:30
 appProdProjectContainer->getAssetic_AssetManagerService() at C:SF2_projectappbootstrap.php.cache:211
 SymfonyComponentDependencyInjectionContainer->get() at C:SF2_projectvendorsymfonyassetic-bundleSymfonyBundleAsseticBundleCacheWarmerAssetManagerCacheWarmer.php:33
 SymfonyBundleAsseticBundleCacheWarmerAssetManagerCacheWarmer->warmUp() at C:SF2_projectvendorsymfonysymfonysrcSymfonyComponentHttpKernelCacheWarmerCacheWarmerAggregate.php:47
 SymfonyComponentHttpKernelCacheWarmerCacheWarmerAggregate->warmUp() at C:SF2_projectvendorsymfonysymfonysrcSymfonyBundleFrameworkBundleCommandCacheWarmupCommand.php:64
 SymfonyBundleFrameworkBundleCommandCacheWarmupCommand->execute() at C:SF2_projectvendorsymfonysymfonysrcSymfonyComponentConsoleCommandCommand.php:238
 SymfonyComponentConsoleCommandCommand->run() at C:SF2_projectvendorsymfonysymfonysrcSymfonyComponentConsoleApplication.php:193
 SymfonyComponentConsoleApplication->doRun() at C:SF2_projectvendorsymfonysymfonysrcSymfonyBundleFrameworkBundleConsoleApplication.php:78
 SymfonyBundleFrameworkBundleConsoleApplication->doRun() at C:SF2_projectvendorsymfonysymfonysrcSymfonyComponentConsoleApplication.php:106
 SymfonyComponentConsoleApplication->run() at C:SF2_projectappconsole:22

有人知道吗?多谢。

问题似乎是Symfony2中的一个错误:如果您希望默认实体管理器在生产环境中作为默认实体管理器工作,则必须将默认实体管理器命名为"default"。

将 app/config/config.yml 中的 doctrine.orm 部分更改为:

doctrine:
  orm:
    auto_generate_proxy_classes: %kernel.debug%
    default_entity_manager: default
    entity_managers:
      event_db:
        connection:   event_db
        mappings:
            MyFirmEventManagerBundle: ~
      default:
        connection:   user_config_db
        mappings:
            MyFirmUserManagerBundle:  ~

一切正常。

好的。最后,经过很长时间,我找到了解决方案:您必须使用 manager_name 选项将实体管理器名称添加到安全定义中:

安全:  编码:    MyFirm\UserManagerBundle\Entity\User:        ID: myfirm_usermanager.password_encoder  供应商:    user_db:        实体:            类: MyFirm\UserManagerBundle\Entity\User            属性:用户名            manager_name:user_config_db

相关内容

  • 没有找到相关文章

最新更新