无法自动连线服务 RefreshedTokenListener:方法构造()的参数"$ttl"是类型提示"int",应显式配置其值



我有一个监听器,它在__construct中有一个名为$ttl的参数,类型提示为int,ttl的值也是以秒为单位的。我从配置YAML文件中获取这个值。

我用$ttl参数声明了该服务,对我来说它似乎是明确声明的。但现在symfony在我修复它之前会失败。我甚至无法清除缓存。

我看到的错误是:

无法自动连接服务RefreshedTokenListener:参数"ttl";方法"__construct((";是类型提示的";int";,您应该显式地配置其值

并且侦听器代码以:开头

class RefreshedTokenListener implements EventSubscriberInterface
{
private int $ttl;
public function __construct(int $ttl)
{
$this->ttl = $ttl;
}
...

并且该服务被声明为:

services:
_defaults:
autowire: true 
autoconfigure: true
UserBundle:
resource: '../../../'
exclude:
- '../../../Domain/Entity/'
- '../../../Infrastructure/Repository/'
- '../../../Infrastructure/DependencyInjection/'
...
app.listener.refreshedtokenlistener:
class: UserBundleApplicationListenersRefreshedTokenListener
arguments:
$ttl: '%gesdinet_jwt_refresh_token.ttl%'

我试图在__construct()$ttl参数中强制设置一个固定编号

arguments:
$ttl: 8990000

但仍然是我应该显式配置其值的错误消息

我看不出哪里出了问题,但它不起作用。我使用的是symfony 5.1,php 7.4.8

我刚刚完全删除了app.listener.refreshedtokenlistener声明行,所以错误应该会消失。但同样的错误仍然存在,所以这个服务必须在某个地方自动声明,这就是我看到的错误。如何查找错误?我在dev.log 上没有看到任何关于这方面的信息

这是因为您使用别名而不是其完整类名来声明服务。目前,您的服务从未自动连接。

你必须这样做:

services:
# ...
app.listener.refreshedtokenlistener:
class: UserBundleApplicationListenersRefreshedTokenListener
arguments:
$ttl: '%gesdinet_jwt_refresh_token.ttl%'
UserBundleApplicationListenersRefreshedTokenListener: '@app.listener.refreshedtokenlistener'

最新更新