简体   繁体   中英

The class 'App\Document\User' was not found in the chain configured namespaces

I have just put in place mongodb with symfony4.1.

When I want to persist a simple User in the database, I got this error (title) :

Uncaught PHP Exception Doctrine\\Common\\Persistence\\Mapping\\MappingException: "The class 'App\\Document\\User' was not found in the chain configured namespaces

在此处输入图片说明

Here my controller :

/**
 * @Route("/mongoTest")
 * @Method("GET")
 * @param DocumentManager $dm
 * @return JsonResponse
 */
public function mongoTest(DocumentManager $dm)
{
    $user = new User();
    $user->setEmail("hello@medium.com");
    $user->setFirstname("Matt");
    $user->setLastname("Matt");
    $user->setPassword(md5("123456"));
    $dm->persist($user);
    $dm->flush();
    return new JsonResponse(array('Status' => 'OK'));
}

Config :

 doctrine_mongodb: connections: default: server: "%mongodb_server%" options: {} default_database: "%mongodb_database_name%" document_managers: default: auto_mapping: true default_commit_options: ~ 

Here my Document :

 <?php namespace App\\Document; use Doctrine\\ODM\\MongoDB\\Mapping\\Annotations as MongoDB; /** * @MongoDB\\Document */ class User { /** * @MongoDB\\Id */ protected $id; /** * @MongoDB\\Field(type="string") */ protected $firstname; /** * @MongoDB\\Field(type="string") */ protected $lastname; /** * @MongoDB\\Field(type="string") */ protected $email; /** * @MongoDB\\Field(type="string") */ protected $password; /** * @MongoDB\\Field(type="date") */ protected $create_date; // ... } 

Does anyone have an idea ?

Thanks a lot !!

I found the answer :

I do not use bundles.

 doctrine_mongodb: connections: default: server: "%mongodb_server%" options: {} default_database: "%mongodb_database_name%" document_managers: default: mappings: # ... App: type: annotation dir: "%kernel.root_dir%/../src/Document" is_bundle: false prefix: App\\Document alias: App default_commit_options: ~ 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM