五分钟了解冷泉
我将在 5 分钟内重读《冷泉》。 它说“UserService 需要 UserGateway,UserGateway 需要 ConfigBean”。 不,不是的! UserService 不需要任何东西。 它不调用 UserGateway。
它所做的只是设置一个变量,它碰巧调用了 userGateway,但它不调用用户网关组件。
帮助我理解这个看似简单的场景!
I'm rereading ColdSpring in 5 minutes.
It says "The UserService needs the UserGateway, and the UserGateway needs the ConfigBean".
No it does not! The UserService does not need anything. It doesn't call UserGateway.
All it does is set a variable that it happens to call userGateway by coincidence, but it doesn't call the User Gateway component.
Help me understand this apparently simple scenario!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须记住,此入门应用程序故意不解释所有内容,以免造成混淆。 配置完成后,示例应用程序将初始化所有三个组件。 UserService CFC 负责设置和获取用户网关组件,用户网关组件负责设置和获取 Config Bean 组件,Config Bean 组件旨在设置和获取应用程序设置(在本例中,只需数据源信息)。
如果你不明白这一切是如何运作的,我现在不会对此太担心; ColdSpring 的参考指南将为您提供一切焦点。
You have to remember that this starter application intentionally doesn't explain everything so as to prevent confusion. When completely configured, the sample application will initialize all three components. The UserService CFC has the responsiblity of setting and getting the User Gateway Component, the User Gateway component has the responsiblity of setting and getting the Config Bean component, and the Config Bean component is designed to set and get application settings (in this case, just datasource information).
I wouldn't fret too much over this for now if you don't understand how it all works; ColdSpring's reference guide will bring it all into focus for you.
“UserService 需要 UserGateway”这一行意味着其中一个函数包含需要 UserGateway 的变量或调用,但 UserService 不一定对其有任何内在需求。 这是 ColdSpring 的核心...管理依赖关系。 如果 UserService 没有配置为注入 UserGateway,那么当创建“恰好”调用或需要 UserGateway 的变量时,它将无法找到所需的 UserGateway,除非您手动实例化它。
例如,查看《ColdSpring 快速入门指南》中“更高级”下的“Factory Beans”。
5 分钟的例子只是一个例子,你没有看到那些需要 UserGateway 的函数中的任何调用,但是当你确实需要它时,你会很高兴它已经为你注入了,这样你就不需要不必自己做。
The line "The UserService needs the UserGateway" means that one of the functions contains a variable or call that needs the UserGateway, not necessarily that the UserService has any intrinsic need for it. This is at the core of what ColdSpring does... manage dependencies. If the UserService was not configured to be injected with the UserGateway, then when a variable that "just happens" to call or need the UserGateway is created, it would not be able to find the needed UserGateway unless you manually instantiated it.
Look under "More Advanced" in the ColdSpring Quickstart Guide at "Factory Beans", for example.
The 5 minute example was just that, an example, you didn't see any calls in those functions that needed the UserGateway, but when you do have a need for it, you'll be glad it was injected for you so that you don't have to do it yourself.