我将我的网站从Symfony 3.4更新到Symfony 4并做了一些改动。但是知道我有这个错误:
您已请求不存在的服务" D"。
这是我的堆栈跟踪:
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException:
You have requested a non-existent service "D".
at vendor\symfony\dependency-injection\Container.php:263
at Symfony\Component\DependencyInjection\Container->get('D')
(vendor\symfony\routing\Loader\DependencyInjection\ServiceRouterLoader.php:38)
at Symfony\Component\Routing\Loader\DependencyInjection\ServiceRouterLoader->getServiceObject('D')
(vendor\symfony\routing\Loader\ObjectRouteLoader.php:55)
at Symfony\Component\Routing\Loader\ObjectRouteLoader->load('D:\\IIS Websites\\Wizard\\src/config/routing.yml', 'service')
(vendor\symfony\config\Loader\DelegatingLoader.php:40)
at Symfony\Component\Config\Loader\DelegatingLoader->load('D:\\IIS Websites\\Wizard\\src/config/routing.yml', 'service')
(vendor\symfony\framework-bundle\Routing\DelegatingLoader.php:70)
at Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader->load('D:\\IIS Websites\\Wizard\\src/config/routing.yml', 'service')
(vendor\symfony\framework-bundle\Routing\Router.php:56)
at Symfony\Bundle\FrameworkBundle\Routing\Router->getRouteCollection()
(vendor\symfony\routing\Router.php:367)
at Symfony\Component\Routing\Router->getMatcherDumperInstance()
(vendor\symfony\routing\Router.php:289)
at Symfony\Component\Routing\Router->Symfony\Component\Routing\{closure}(object(ResourceCheckerConfigCache))
at call_user_func(object(Closure), object(ResourceCheckerConfigCache))
(vendor\symfony\config\ResourceCheckerConfigCacheFactory.php:43)
at Symfony\Component\Config\ResourceCheckerConfigCacheFactory->cache('D:\\IIS Websites\\Wizard\\var\\cache\\dev/srcDevDebugProjectContainerUrlMatcher.php', object(Closure))
(vendor\symfony\routing\Router.php:302)
at Symfony\Component\Routing\Router->getMatcher()
(vendor\symfony\routing\Router.php:256)
at Symfony\Component\Routing\Router->matchRequest(object(Request))
(vendor\symfony\http-kernel\EventListener\RouterListener.php:109)
at Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(object(GetResponseEvent), 'kernel.request', object(EventDispatcher))
(vendor\symfony\event-dispatcher\EventDispatcher.php:212)
at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(array(object(DebugHandlersListener), 'configure'), array(object(ValidateRequestListener), 'onKernelRequest'), array(object(SessionListener), 'onKernelRequest'), array(object(FragmentListener), 'onKernelRequest'), array(object(RouterListener), 'onKernelRequest'), array(object(ResolveControllerNameSubscriber), 'onKernelRequest'), array(object(LocaleListener), 'onKernelRequest'), array(object(TranslatorListener), 'onKernelRequest'), array(object(TraceableFirewallListener), 'onKernelRequest')), 'kernel.request', object(GetResponseEvent))
(vendor\symfony\event-dispatcher\EventDispatcher.php:44)
at Symfony\Component\EventDispatcher\EventDispatcher->dispatch('kernel.request', object(GetResponseEvent))
(vendor\symfony\http-kernel\HttpKernel.php:125)
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
(vendor\symfony\http-kernel\HttpKernel.php:66)
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
(vendor\symfony\http-kernel\Kernel.php:190)
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
(public\index.php:34)
提前感谢您的帮助。
答案 0 :(得分:5)
从Symfony 3.4升级到4.0时,我遇到了同样的问题。我目前正在使用路由注释,而使用Symfony 3则不是这样。
看来我的framework.yaml路由器配置(/ config / packages /)出错了。
framework:
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
实际上它是来自旧config.yml文件的复制/粘贴。当我使用路由注释时,删除框架配置中的路由器密钥解决了我的问题。但您可能还需要指向'资源'下的特定路由配置文件。
您可以使用以下命令检查指定的资源路径是否正确:
php bin/console debug:config framework
希望这会有所帮助!
答案 1 :(得分:0)
提前道歉,因为我没有实际答案,但这不符合评论。
// From the stack trace
ObjectRouterLoader->load(D:\\blahblah)
// ObjectRouterLoader::load()
public function load($resource, $type = null)
{
$parts = explode(':', $resource);
if (2 != count($parts)) {
throw new \InvalidArgumentException(sprintf('Invalid resource "%s" passed to the "service" route loader: use the format "service_name:methodName"', $resource));
}
$serviceString = $parts[0];
$method = $parts[1];
$loaderObject = $this->getServiceObject($serviceString);
路由对象加载器实际上需要一个像service:method这样的字符串。你的Windows D驱动器路径也有一个冒号,所以它通过初始检查,但后来想加载一个名为D的服务。
那么为什么使用无效参数调用ObjectRouteLoader :: load?我无法从堆栈跟踪中回答,但我猜你的应用程序的Kernel :: configureRoutes或者你的routes.yaml文件中有一个问题。
我所能提出的建议是,您尝试撤消与路线相关的任何操作。如果这没有帮助,那么可以从一个新的S4骨架项目开始,一次移动你的S3应用程序。