2

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

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

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

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

security:
  encoders:
    MyFirm\UserManagerBundle\Entity\User:
        id: myfirm_usermanager.password_encoder

  providers:
    user_db:
        entity: 
            class: MyFirm\UserManagerBundle\Entity\User
            property: username 

app/config/config.yml 中的教义.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_project\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\MappingException.php:38
 Doctrine\Common\Persistence\Mapping\MappingException::classNotFoundInNamespaces() at C:\SF2_project\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain.php:114
 Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain->loadMetadataForClass() at C:\SF2_project\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\ClassMetadataFactory.php:112
 Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata() at C:\SF2_project\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory.php:302
 Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata() at C:\SF2_project\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory.php:205
 Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor() at C:\SF2_project\vendor\doctrine\orm\lib\Doctrine\ORM\EntityManager.php:268
 Doctrine\ORM\EntityManager->getClassMetadata() at C:\SF2_project\app\cache\prod\jms_diextra\doctrine\EntityManager_5075a0dd6e27a.php:345
 EntityManager5075a0dd6e27a_546a8d27f194334ee012bfe64f629947b07e4919\__CG__\Doctrine\ORM\EntityManager->getClassMetadata() at C:\SF2_project\vendor\symfony\symfony\src\Symfony\Bridge\Doctrine\Security\User\EntityUserProvider.php:39
 Symfony\Bridge\Doctrine\Security\User\EntityUserProvider->__construct() at C:\SF2_project\app\cache\prod\appProdProjectContainer.php:1132
 appProdProjectContainer->getSecurity_User_Provider_Concrete_UserDbService() at C:\SF2_project\app\bootstrap.php.cache:211
 Symfony\Component\DependencyInjection\Container->get() at C:\SF2_project\app\cache\prod\appProdProjectContainer.php:1121
 appProdProjectContainer->getSecurity_User_Provider_Concrete_ChainProviderService() at C:\SF2_project\app\bootstrap.php.cache:211
 Symfony\Component\DependencyInjection\Container->get() at C:\SF2_project\app\cache\prod\appProdProjectContainer.php:1105
 appProdProjectContainer->getSecurity_Authentication_ManagerService() at C:\SF2_project\app\bootstrap.php.cache:211
 Symfony\Component\DependencyInjection\Container->get() at C:\SF2_project\app\cache\prod\appProdProjectContainer.php:552
 appProdProjectContainer->getSecurity_ContextService() at C:\SF2_project\app\bootstrap.php.cache:211
 Symfony\Component\DependencyInjection\Container->get() at C:\SF2_project\app\cache\prod\appProdProjectContainer.php:1002
 appProdProjectContainer->getTwigService() at C:\SF2_project\app\bootstrap.php.cache:211
 Symfony\Component\DependencyInjection\Container->get() at C:\SF2_project\app\cache\prod\appProdProjectContainer.php:30
 appProdProjectContainer->getAssetic_AssetManagerService() at C:\SF2_project\app\bootstrap.php.cache:211
 Symfony\Component\DependencyInjection\Container->get() at C:\SF2_project\vendor\symfony\assetic-bundle\Symfony\Bundle\AsseticBundle\CacheWarmer\AssetManagerCacheWarmer.php:33
 Symfony\Bundle\AsseticBundle\CacheWarmer\AssetManagerCacheWarmer->warmUp() at C:\SF2_project\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate.php:47
 Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate->warmUp() at C:\SF2_project\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Command\CacheWarmupCommand.php:64
 Symfony\Bundle\FrameworkBundle\Command\CacheWarmupCommand->execute() at C:\SF2_project\vendor\symfony\symfony\src\Symfony\Component\Console\Command\Command.php:238
 Symfony\Component\Console\Command\Command->run() at C:\SF2_project\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php:193
 Symfony\Component\Console\Application->doRun() at C:\SF2_project\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php:78
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at C:\SF2_project\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php:106
 Symfony\Component\Console\Application->run() at C:\SF2_project\app\console:22

有人有任何线索吗?非常感谢。

4

2 回答 2

2

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

将 app/config/config.yml 中的教义.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:  ~

一切正常。

于 2012-10-11T07:45:41.557 回答
0

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

安全:
  编码器:
    MyFirm\UserManagerBundle\Entity\User:
        id: myfirm_usermanager.password_encoder

  提供者:
    用户数据库:
        实体:
            类:MyFirm\UserManagerBundle\Entity\User
            属性:用户名
            manager_name:user_config_db
于 2014-09-16T10:50:30.890 回答