Drupal 8.2.3站点故障:RouteSubscriber类不存在及恢复问题求助
解决Drupal 8.2.3站点恢复后持续显示维护页并出现ReflectionException的问题
问题背景
你原本运行正常的Drupal 8.2.3站点遭遇攻击后,通过修改.htaccess临时下线,恢复更新后始终显示维护页,本地副本更新核心、新建站点导入原有数据库都无法解决,PHP错误日志显示:
[22-May-2018 17:35:48 UTC] ReflectionException: Class Drupal\token\Routing\RouteSubscriber does not exist in f:\example\core\lib\Drupal\Core\DependencyInjection\Compiler\RegisterEventSubscribersPass.php on line 30 #0 f:\example\core\lib\Drupal\Core\DependencyInjection\Compiler\RegisterEventSubscribersPass.php(30): ReflectionClass->__construct('Drupal\\token\\Ro...') #1 f:\example\vendor\symfony\dependency-injection\Compiler\Compiler.php(107): Drupal\Core\DependencyInjection\Compiler\RegisterEventSubscribersPass->process(Object(Drupal\Core\DependencyInjection\ContainerBuilder)) #2 f:\example\vendor\symfony\dependency-injection\ContainerBuilder.php(593): Symfony\Component\DependencyInjection\Compiler\Compiler->compile(Object(Drupal\Core\DependencyInjection\ContainerBuilder)) #3 f:\example\core\lib\Drupal\Core\DrupalKernel.php(1254): Symfony\Component\DependencyInjection\ContainerBuilder->compile() #4 f:\example\core\lib\Drupal\Core\DrupalKernel.php(866): Drupal\Core\DrupalKernel->compileContainer() #5 f:\example\core\lib\Drupal\Core\DrupalKernel.php(461): Drupal\Core\DrupalKernel->initializeContainer() #6 f:\example\core\lib\Drupal\Core\DrupalKernel.php(651): Drupal\Core\DrupalKernel->boot() #7 f:\example\index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #8 {main}
解决方案
这个错误明确指向Drupal\token\Routing\RouteSubscriber类不存在,说明Token模块的文件可能损坏、丢失,或者缓存、版本兼容性出了问题。按以下步骤排查:
检查Token模块文件完整性
首先找到站点的Token模块目录(通常是modules/contrib/token,Token属于第三方贡献模块),查看src/Routing/RouteSubscriber.php文件是否存在。如果文件缺失或者内容损坏,下载和Drupal 8.2.3兼容的Token模块版本(选适配8.2.x核心的8.x-1.x分支早期版本),替换掉现有模块目录。强制清除Drupal缓存
Drupal的缓存可能保留了旧的类映射信息,即使文件恢复了也会报错。可以通过两种方式清除:- 若能使用Drush,直接运行命令:
drush cr(Drupal 8的缓存重建命令) - 若无Drush权限,手动删除
sites/default/files下的php目录、所有cache_开头的缓存目录,以及config_*目录里的临时缓存文件(操作前建议备份sites/default/files目录)。
- 若能使用Drush,直接运行命令:
检查并关闭Drupal内置维护模式
有时候修改.htaccess下线后,Drupal本身的维护模式可能被意外开启。可以通过数据库检查:- 登录数据库管理工具(比如phpMyAdmin),找到
config表 - 搜索
name字段为system.site的记录,查看data字段中的maintenance_mode值,如果是1(开启状态),改成0即可。
或者用Drush命令快速关闭:drush state-set system.maintenance_mode 0
- 登录数据库管理工具(比如phpMyAdmin),找到
重新安装Token模块(若上述步骤无效)
如果模块文件没问题但还是报错,可能是模块注册信息损坏。尝试先卸载再重新安装:- 运行Drush命令卸载:
drush pm-uninstall token -y - 重新下载对应版本的Token模块到
modules/contrib目录 - 启用模块:
drush pm-enable token -y - 再次重建缓存:
drush cr
- 运行Drush命令卸载:
内容的提问来源于stack exchange,提问作者Andrew Dean
相关产品推荐
相关产品推荐

