我听说了很多关于Spring的事情,人们在网上说Spring是一个很好的web开发框架。简而言之,Spring框架到底是用来干什么的?为什么我要用它而不是纯Java。
当前回答
Spring非常适合将类实例粘合在一起。你知道你的Hibernate类总是需要一个数据源,Spring将它们连接在一起(也有一个数据源的实现)。
数据访问对象总是需要Hibernate访问,Spring将Hibernate类连接到dao中。
此外,Spring基本上为您提供了一系列库的可靠配置,并指导您应该使用哪些库。
Spring真的是一个很棒的工具。(我说的不是Spring MVC,只是基本框架)。
其他回答
过去,Spring只是一个依赖注入框架(Guice, PicoContainer,…),但现在它是构建企业应用程序的完整解决方案。
spring依赖注入,当然,spring的核心仍然在那里(你可以在这里查看其他好的答案),但是还有更多来自spring的答案……
Spring现在有很多项目,每个项目都有一些子项目(http://spring.io/projects)。当有人谈到spring时,你一定要弄清楚他说的是什么spring项目,是仅仅是spring核心,也就是spring框架,还是另一个spring项目。
值得一提的春季项目有:
Spring Security - http://projects.spring.io/spring-security/ Spring Webservices - http://projects.spring.io/spring-ws/ Spring集成- http://projects.spring.io/spring-integration/
如果你的应用程序需要一些更指定的功能,你也可以在那里找到:
Spring批处理框架设计,使批处理能够开发 批处理应用程序 Spring HATEOAS基于HATEOAS原理轻松创建REST API Spring Mobile和Spring Andriod用于移动应用程序开发 Spring Shell构建一个功能齐全的Shell(又名命令行)应用程序 Spring Cloud和Spring Cloud Data Flow用于云应用程序
还有一些小项目,比如spring-social-facebook (http://projects.spring.io/spring-social-facebook/)
你可以使用spring进行web开发,因为它有spring MVC模块,这是spring框架项目的一部分。或者你可以将spring与另一个web框架一起使用,比如struts2。
Spring框架绝对适合web开发,尤其适合restful api服务。
这是因为它的依赖注入和与其他模块的集成,如spring security、spring aop、mvc框架、微服务
在任何应用程序中,安全性都很可能是一个需求。 如果您的目标是构建一个需要长期维护的产品,那么您将需要利用Aop的概念。 如果你的应用程序有太多的流量,从而增加了负载,你需要使用微服务的概念。
Spring在一个平台中提供了所有这些特性。支持多个模块。 最重要的是,spring是开源的和可扩展的框架,在生命周期中到处都有钩子来集成自定义代码。
Spring Data是一个提供与您的项目集成的项目。
所以弹簧几乎可以满足所有的需求。
Spring最初是一个相当简单的依赖注入系统。现在它很大,里面什么都有(除了众所周知的厨房水槽)。
但不用担心,它是模块化的,所以你可以只使用你想要的部件。
去看看一切从哪里开始尝试:
http://www.amazon.com/Expert-One-Design-Development-Programmer/dp/0764543857/ref=sr_1_1?ie=UTF8&s=books&qid=1246374863&sr=1-1
它可能很旧,但却是一本好书。
关于另一本关于春天的好书,请看:
http://www.amazon.com/Professional-Java-Development-Spring-Framework/dp/0764574833/ref=sr_1_2?ie=UTF8&s=books&qid=1246374863&sr=1-2
它还引用了较老版本的Spring,但绝对值得一看。
春天有三样东西。
Spring handles Dependency Injection and I recommend you read Martin Fowler's excellent introduction on dependency injection. The second thing Spring does is wrap excellent Java libraries in a very elegant way to use in your applications. For a good example see how Spring wraps Task Executors and Quartz Scheduler. Thirdly Spring provides a bunch of implementations of web stuff like REST, an MVC web framework and more. They figure since you are using Spring for the first two, maybe you can just use it for everything your web app needs.
The problem is that Spring DI is really well thought out, the wrappers around other things are really well thought out in that the other things thought everything out and Spring just nicely wraps it. The Spring implementations of MVC and REST and all the other stuff is not as well done (YMMV, IMHO) but there are exceptions (Spring Security is da bomb). So I tend to use Spring for DI, and its cool wrappers but prefer other stuff for Web (I like Tapestry a lot), REST (Jersey is really robust), etc.
简而言之,我认为Spring是应用程序中的“粘合剂”。它用于集成不同的框架和您自己的代码。
推荐文章
- 如果我同步了同一个类上的两个方法,它们能同时运行吗?
- 如何减去X天从一个日期对象在Java?
- Java标识符中的“连接字符”是什么?
- 一对多、多对一、多对多的区别?
- 从枚举中选择一个随机值?
- 如何从URL获取参数与JSP
- 如何在Eclipse中生成Javadoc注释?
- 找到java类从哪里加载
- 从集合中随机选取一个元素
- 为什么x == (x = y)和(x = y) == x不一样?
- 什么Java 8流。收集等价物可在标准Kotlin库?
- 等待未来的名单
- 如何检查JSON键是否存在?
- 为什么MongoDB Java驱动在条件中使用随机数生成器?
- 即使从未抛出异常,使用try-catch块的代价是否昂贵?