Spring 应用程序设计的重要性
我一直在研究如何在我的 java 应用程序中使用 spring 框架。
这是一种看待一般编程的不同方式,我说的是 DI 和 AOP!
对我来说,将基本部分分解为可重用组件的水平似乎需要大量的前期工作(在设计过程中)。我想知道什么时候我才能知道它已经准备好进行编码(这可能只是经验)
猜猜我正在看一些技巧?你应该从哪里开始?看来它必须从一开始就进行完美的设计,以避免这种紧密耦合的情况,这种情况在我使用过的其他应用程序中似乎很常见(不一定是我自己制作的)我什么时候知道是时候拍摄我的负载和代码了?
请不要标记这是主观的或我只是想从社区得到一些诚实和体面的建议。
提前致谢!
I've been taking a look into using the spring framework for my java apps.
It is such a different way of looking at programming in general, i'm talking about DI and AOP!
The level of breaking the fundamental parts up into reusable components to me seems like a lot of work up front(in the design process). Im questioning the part of when I'll know its ready to get coding(this might just be in experience)
Guess I am looking at some tips? Where should you begin? It seems it has to be perfectly designed from the get go to avoid this tightly coupling scenario that seems so common amongst other applications I have worked with(not necessarily made them myself) When will I know its time to shoot my load and code?
Please don't tag this is a subjective or something I just want some honest and decent advice from the community.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从未见过一个应用程序是预先完全设计的(在实现层面上)。相反,无论您是否使用 Spring,重构都是(也应该是)该过程的一部分。
也许您对 Spring 框架的范围感到不知所措。别这样。主要目标是使用依赖注入来反转控制,并允许您编写简单的 POJOS 来构建您的应用程序。它不会使应用程序变得更复杂,而是使应用程序变得更简单。
这并不是说 Spring 的一切都是一帆风顺的——事实并非如此。但你可以一边学习一边学习更复杂的东西。
为了回应您的评论,请将 spring 配置视为您的类的元数据。您不能使用未定义的类来配置 Spring。 Spring 为您处理定义的 bean 的创建和生命周期。因此,如果 ClassA 依赖于 ClassB,那么当创建 ClassA 时,框架将为您创建依赖项(并注入它们)。
Ive never seen an app that was completely designed (on the implementation level) up front. On the contrary, refactoring is (well should be) part of the process, regardless of whether or not you use Spring.
Perhaps you are overcome by the scope of the Spring framework. Don't be. The main goal is to use dependency injection to invert control, and allow you to write simple POJOS to structure your app. It doesn't make an app more complicated, it makes one simpler.
This is not to say that everything with Spring is strait forward - it isn't. But you can learn the more complicated things as you go.
In response to your comment, think of the spring configuration as metadata for your class. You cannot configure Spring with a class you have not defined. Spring handles the creation and life cycles of the defined beans for you. So if ClassA depends on ClassB, then when a ClassA gets created, the framework will create the dependencies (and inject them) for you.
当我使用 Spring DI 时,我意识到我不再花费太多时间来确定是否实例化对象,或者从某些服务中查找它们,或者对它们做其他事情。
您可能也不应该过度使用 DI。一个好的指导方针是将应用程序分成您想要进行单元测试的“接缝”处的 bean。类似的方法 - 在应用程序层之间的“接缝”处:数据访问、业务逻辑服务、UI。
When I went with Spring DI, I realized that I stopped spending so much time figuring out whether to instantiate objects, or look them up from some service or do something else to them.
You probably shouldn't go overboard with DI either. A good guideline would be to split app into beans at the "seams" where you would want to do unit tests. Similar approach - at the "seams" between application layers: data access, vs. business logic services, vs. UI.