这是因为你正在创造 AppCtxConfig 作为普通的豆,它不是。
AppCtxConfig
正如评论员建议的那样,添加组件扫描并将base-package设置为配置类所在的包:
<!-- Scan the JavaConfig --> <context:component-scan base-package="com.somegroup.app" />
如果您的应用程序包是根包,并且包含所有子包,请添加一个新的配置包并移动 AppCtxConfig 在里面。
所以添加:
<!-- Scan the config package with AppCtxConfig inside it --> <context:component-scan base-package="com.somegroup.app.config" />