简体   繁体   English

Symfony 3.4-服务“ AppBundle \\ Controller \\ [some] Controller”依赖于不存在的服务“ Symfony \\ Component \\ Serializer \\ Serializer”

[英]Symfony 3.4 - The service “AppBundle\Controller\[some]Controller” has a dependency on a non-existent service “Symfony\Component\Serializer\Serializer”

(1/1) ServiceNotFoundException The service "AppBundle\\Controller\\FormController" has a dependency on a non-existent service "Symfony\\Component\\Serializer\\Serializer". (1/1)ServiceNotFoundException服务“ AppBundle \\ Controller \\ FormController”对不存在的服务“ Symfony \\ Component \\ Serializer \\ Serializer”具有依赖性。

My controller is: 我的控制器是:

<?php

namespace AppBundle\Controller;

use AppBundle\Service\SubscriberService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class FormController extends Controller
{
    private $subscriber;

    public function __construct(SubscriberService $subscriber)
    {
        $this->subscriber = $subscriber;
    }

    /**
     * @Route("/", name="form")
     */
    public function indexAction(): Response
    {
        $categories = $this->subscriber->getCategories();

        return $this->render('subscription/form.html.twig', ['categories' => $categories]);
    }

    /**
     * @param Request $request
     * @return Response
     * @Route("/save", name="save_subscriber")
     */
    public function save(Request $request): Response
    {
        $this->subscriber->save($request->get('name'), $request->get('email'), $request->get('categories'));
    }
}

Services.yml: Services.yml:

# Learn more about services, parameters and containers at
# https://symfony.com/doc/current/service_container.html
parameters:
    #parameter_name: value

services:
    # default configuration for services in *this* file
    _defaults:
        # automatically injects dependencies in your services
        autowire: false
        # automatically registers your services as commands, event subscribers, etc.
        autoconfigure: true
        # this means you cannot fetch services directly from the container via $container->get()
        # if you need to do this, you can override this setting on individual services
        public: false

    # makes classes in src/AppBundle available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    AppBundle\:
        resource: '../../src/AppBundle/*'
        # you can exclude directories or files
        # but if a service is unused, it's removed anyway
        exclude: '../../src/AppBundle/{Entity,Tests}'

    # controllers are imported separately to make sure they're public
    # and have a tag that allows actions to type-hint services
    AppBundle\Controller\:
        resource: '../../src/AppBundle/Controller'
        public: true
        tags: ['controller.service_arguments']

    # add more services, or override services that need manual wiring
    # AppBundle\Service\ExampleService:
    #     arguments:
    #         $someArgument: 'some_value'

    AppBundle\Service\SubscriberService:
        arguments:
            $validator: '@Symfony\Component\Validator\Validator\ValidatorInterface'
            $subscriberRepository: '@AppBundle\Repository\SubscriberRepository'

    AppBundle\Controller\FormController:
        arguments:
            $subscriber: '@AppBundle\Service\SubscriberService'

    AppBundle\Repository\SubscriberRepository:
        arguments:
            $serializer: '@Symfony\Component\Serializer\Serializer'

For me error does not make any sense. 对我来说,错误没有任何意义。 We can clearly see that there is no such dependency in the controller. 我们可以清楚地看到,控制器中没有这种依赖性。

How to fix this? 如何解决这个问题?

Your SubscriberRepository has a dependency on serializer. 您的SubscriberRepository依赖于序列化程序。 Because serializer service is not available by default, you have to turn it on, activate it in your configuration before using: 由于默认情况下序列化器服务不可用,因此您必须将其打开,请在配置中将其激活,然后再使用:

# app/config/config.yml
framework:
    # ...
    serializer:
        enabled: true

More Information: http://symfony.com/doc/3.4/serializer.html 更多信息: http : //symfony.com/doc/3.4/serializer.html

Thanks! 谢谢!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Symfony 3.4 - 服务“Symfony\\Component\\Ldap\\Ldap”依赖于不存在的服务“Symfony\\Component\\Ldap\\Adapter\\ExtLdap\\Adapter” - Symfony 3.4 - The service "Symfony\Component\Ldap\Ldap" has a dependency on a non-existent service "Symfony\Component\Ldap\Adapter\ExtLdap\Adapter" Symfony2错误:服务“模板”依赖于不存在的服务“ templating.globals” - Symfony2 error: The service “templating” has a dependency on a non-existent service “templating.globals” Symfony:服务...依赖于不存在的参数kernel.secret - Symfony: The service … has a dependency on a non-existent parameter kernel.secret Symfony突然失败,“服务”session.storage.metadata_bag“依赖于不存在的参数” - Symfony is suddenly failing with “The service ”session.storage.metadata_bag“ has a dependency on a non-existent parameter” 在 Symfony 4.4 中覆盖 Controller(装饰)-“您请求的服务不存在” - Overriding Controller in Symfony 4.4 (Decorates) - “You have requested a non-existent service” Symfony 2称不存在的服务“路由器” - Symfony 2 calling non-existent service “router” Symfony 3.2“security.firewall.map.context.main”依赖于不存在的服务^我的身份验证处理程序^ - Symfony 3.2 “security.firewall.map.context.main” has a dependency on a non-existent service ^my authentication handler^ Symfony 2,ServiceNotFoundException,不存在的服务“ templating.engine.php” - Symfony 2, ServiceNotFoundException, non-existent service “templating.engine.php” 如何在Symfony 4中配置不存在的服务? - How can I configure a non-existent service in Symfony 4? Symfony 4.1:你请求了一个不存在的服务“主义” - Symfony 4.1 : You have requested a non-existent service "doctrine"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM