ASDF在SBCL脚本模式下加载Ningle项目仅运行main文件,路由失效
问题分析
核心原因是ASDF系统定义缺少文件间的依赖声明:用sbcl --script加载系统时,ASDF会严格按照定义的依赖关系加载文件,而你的main.lisp没有依赖其他模块,导致仅加载了主文件,包含路由定义的user-controller.lisp、业务逻辑模块等都未被加载,路由自然无法生效。
LEM环境下正常是因为编辑器或REPL环境可能自动帮你处理了依赖加载,或是你之前手动加载过其他文件,脚本模式下则没有这个“兜底”逻辑。
解决方案
修改ASDF系统定义,给main文件添加对其他模块的依赖声明,让ASDF加载main时自动触发所有依赖文件的加载。修改后的系统定义如下:
(defsystem "rest-api" :version "0.1.0" :defsystem-depends-on (:deploy) :build-operation "deploy-op" :build-pathname "rest-api" :entry-point "rest-api::main" :author "" :license "" :depends-on (#:clack #:ningle #:mito #:yason #:ironclad #:jose #:clack-handler-hunchentoot) :components ((:module "src" :components ((:file "main" :depends-on ("model" "controller" "service" "utils")) (:module "model" :components ((:file "user") (:file "admin"))) (:module "controller" :components ((:file "user-controller"))) (:module "service" :components ((:file "user-service") (:file "auth-service"))) (:module "utils" :components ((:file "json-util"))) ))) :description "" :in-order-to ((test-op (test-op "rest-api/tests"))))
额外优化建议
user-controller.lisp中定义了user-controller包但实际使用rest-api包,建议统一包定义避免混淆:(defpackage :rest-api.controller.user (:use :cl :rest-api)) (in-package :rest-api.controller.user)- 可以给子模块也添加依赖声明,比如
user-controller依赖user-service,在对应文件定义中添加:depends-on ("../service/user-service"),让ASDF更精准地控制加载顺序。
内容的提问来源于stack exchange,提问作者felipebubu
相关产品推荐
相关产品推荐

