Dependency on a non-existent service "doctrine.orm.metadata.annotation_reader"

Dependency on a non-existent service "doctrine.orm.metadata.annotation_reader"

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Dependency on a non-existent service "doctrine.orm.metadata.annotation_reader"

When upgrading a Symfony application, particularly when moving from an older Doctrine setup to version 2.x of doctrine/orm on PHP 8.2, you may encounter a hard stop during the build process. The error message The service "doctrine.orm.default_annotation_metadata_driver" has a dependency on a non-existent service "doctrine.orm.metadata.annotation_reader" is not a configuration syntax error; it is a signal that the service container cannot resolve a specific internal Doctrine component required for metadata loading.

This issue typically arises when using auto_mapping: true combined with entity definitions that rely on attributes (annotations) or specific naming strategies, while the underlying bundle version expects a different service architecture. In your specific case, the mismatch occurs because the default_annotation_metadata_driver is attempting to instantiate an annotation_reader, which has been deprecated and removed in favor of attribute-based metadata reading in modern Doctrine versions.

The immediate workaround you discovered—commenting out the mappings section in doctrine.yaml—confirms that the configuration itself isn't broken, but rather the driver mechanism is misaligned with your installed packages. By disabling the mapping, you bypass the need for the annotation reader entirely, which is why Composer succeeds. However, this results in the subsequent error: Could not find the entity manager for class App\Entity\Token. This happens because Doctrine is no longer scanning the src/Entity directory to register your classes as managed entities.

To resolve this without disabling your entity mappings, you need to align your configuration with the current expectations of Doctrine ORM 2.x. The most direct fix involves switching from attribute-based or annotation-based metadata drivers to a driver that explicitly supports your entity location strategy or removing the reliance on the deprecated reader service.

First, inspect your doctrine.yaml file. If you are defining entities using attributes (PHP 8+ features), ensure you are not inadvertently configuring an annotation driver. The configuration provided in your source material uses auto_mapping: true, which tells Doctrine to scan bundles and non-bundle directories for entity classes based on the defined prefix.

The error suggests that the service container is trying to initialize a metadata driver that relies on an old annotation_reader. In Symfony 6.2 with Doctrine ORM 2.14+, this specific service often does not exist unless explicitly configured via legacy drivers.

Here is how to align your configuration:

  1. Remove Legacy Drivers: Ensure you are not defining a custom metadata_cache or default_annotation_metadata_driver that points to the non-existent reader.
  2. Verify Entity Location: Since you are using auto_mapping: true, Doctrine expects to find entities in directories specified by the dir attribute within your mappings. Your current config points to %kernel.project_dir%/src/Entity. Ensure this path is correct and that the App\Entity namespace matches the file structure exactly.
  3. Explicit Mapping vs. Auto-Mapping: While auto_mapping: true works, sometimes defining the mapping explicitly without relying on the annotation reader resolves service container issues. You can keep your current mappings but ensure no legacy driver services are registered in the container configuration.

If you are using attributes for entity definitions (e.g., #[ORM\Entity]), Doctrine 2.x handles these natively without needing an annotation reader. The error implies that some part of your setup is still trying to use the old annotation scanning mechanism.

Check your services.yaml or any custom service definition files. If you have defined a custom driver or if a third-party bundle is injecting dependencies expecting the old annotation_reader, you may need to update those definitions or remove them.

If you do not require annotation-based metadata (which is standard for PHP 8.2+ projects using attributes), you can safely remove any configuration that attempts to instantiate an annotation reader. The cleanest path forward for a Symfony 6.2 + PHP 8.2 stack with Doctrine ORM 2.14 is to rely entirely on attribute discovery and ensure the default_annotation_metadata_driver is not forcing a dependency on the removed service.

In many cases, simply ensuring that your doctrine.yaml does not define a custom driver for annotations and letting Symfony's default configuration handle the entity manager initialization resolves the "non-existent service" error. If you must use annotation-based metadata (e.g., @ORM\Entity), note that Doctrine 2.x still supports it, but the underlying implementation has shifted away from the specific annotation_reader service that your error log references. You may need to check if a specific bundle requires an explicit driver definition or if a version mismatch in doctrine/doctrine-bundle is causing the container to compile incorrectly.

Updating doctrine/doctrine-bundle and doctrine/orm to their latest stable versions compatible with Symfony 6.2 often resolves these service resolution issues, as newer patch releases have refined how they handle metadata drivers internally.

Our network