Spring Dependencies and Depending on Spring
来源:互联网 发布:从其他excel导入数据 编辑:程序博客网 时间:2024/06/09 10:00
Spring的依赖和被依赖
Although Spring provides integration and support for a huge range of enterprise and other external tools, it intentionally keeps its mandatory dependencies to an absolute minimum: you shouldn’t have to locate and download (even automatically) a large number of jar libraries in order to use Spring for simple use cases. For basic dependency injection there is only one mandatory external dependency, and that is for logging (see below for a more detailed description of logging options).
虽然Spring为大量企业和其他扩展工具提供了集成以及支持,有意识的将他的依赖性保持在最低的程度:有不必因为要使用Spring做简单的用例,来定位以及下载(自动)大量的jar包。对于基本的依赖注入。只有一个强制的外部依赖关系,也就是下文中的日志记录。
Next we outline the basic steps needed to configure an application that depends on Spring, first with Maven and then with Gradle and finally using Ivy. In all cases, if anything is unclear, refer to the documentation of your dependency management system, or look at some sample code - Spring itself uses Gradle to manage dependencies when it is building, and our samples mostly use Gradle or Maven.
接下来,我们概述下配置Spring 依赖的步骤,首先是使用Maven,然后是 Grable最后是lvy。在任何情况下,如果有任何不清的,请参看请使用的依赖管理系统的文档,或者查看一些示例代码,Spring 本身使用Gradle管理依赖,我们的示例中大多数使用Gradle和Maven。
Maven Dependency Management(使用Maven进行依赖管理)
If you are using Maven for dependency management you don’t even need to supply the logging dependency explicitly. For example, to create an application context and use dependency injection to configure an application, your Maven dependencies will look like this:
如果你使用Maven进行依赖管理,你甚至不需要明确地提供日志管理的依赖。例如,要创建应用程序的上下文,并使用依赖注册来配置你的应用程序,你的Maven依赖将会如下所示。
<dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.0.0.BUILD-SNAPSHOT</version> <scope>runtime</scope> </dependency></dependencies>
That’s it. Note the scope can be declared as runtime if you don’t need to compile against Spring APIs, which is typically the case for basic dependency injection use cases.
那么,需要注意的是如果不需要编译Spring Api 那么可以将Scope 设置未 runtime,这是基本的依赖注入用例
The example above works with the Maven Central repository. To use the Spring Maven repository (e.g. for milestones or developer snapshots), you need to specify the repository location in your Maven configuration. For full releases:
上面的例子应用于使用Maven Central的情况下,要使用Spring Maven 库的时候,你需要在Maven中配置仓库的地址
<repositories> <repository> <id>io.spring.repo.maven.release</id> <url>http://repo.spring.io/release/</url> <snapshots><enabled>false</enabled></snapshots> </repository></repositories>
对于 milestones:
<repositories> <repository> <id>io.spring.repo.maven.milestone</id> <url>http://repo.spring.io/milestone/</url> <snapshots><enabled>false</enabled></snapshots> </repository></repositories>
对于 snapshots:
<repositories> <repository> <id>io.spring.repo.maven.snapshot</id> <url>http://repo.spring.io/snapshot/</url> <snapshots><enabled>true</enabled></snapshots> </repository></repositories>
Maven “Bill Of Materials” Dependency
It is possible to accidentally mix different versions of Spring JARs when using Maven. For example, you may find that a third-party library, or another Spring project, pulls in a transitive dependency to an older release. If you forget to explicitly declare a direct dependency yourself, all sorts of unexpected issues can arise.
使用Maven时,可能会意外的混淆不同版本的Spring Jar文件,例如,你可能会发现一个三方的库或者另一个Spring项目 依赖一个旧的版本,如果你忘记了声明版本,那么可能会出现各种意想不到的结果。
To overcome such problems Maven supports the concept of a “bill of materials” (BOM) dependency. You can import the spring-framework-bom in your dependencyManagement section to ensure that all spring dependencies (both direct and transitive) are at the same version.
为了克服这些问题,Maven支持BOM 概念,你可以将spring-framework-bom 导入到dependencyManagement中,以确定所有的依赖版本都是相同的
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-framework-bom</artifactId> <version>5.0.0.BUILD-SNAPSHOT</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies></dependencyManagement>
An added benefit of using the BOM is that you no longer need to specify the attribute when depending on Spring Framework artifacts:
使用BOM的另一个好处时 你不在需要指定Spring Framework 组件的版本了。
<dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </dependency><dependencies>
Gradle Dependency Management
Gradle 依赖管理
To use the Spring repository with the Gradle build system, include the appropriate URL in the repositories section:
使用Gradle构建系统来构建Spring的资源库,你需要在repositories部分添加相应的URI
repositories { mavenCentral() // and optionally... maven { url "http://repo.spring.io/release" }}
You can change the repositories URL from /release to /milestone or /snapshot as appropriate. Once a repository has been configured, you can declare dependencies in the usual Gradle way:
可以根据需要把repositories URL中的/release修改为/milestone或/snapshot。一旦仓库配置好了,就可以按Gradle的方式声明依赖关系了
dependencies { compile("org.springframework:spring-context:5.0.0.BUILD-SNAPSHOT") testCompile("org.springframework:spring-test:5.0.0.BUILD-SNAPSHOT")}
Ivy Dependency Management
使用lvy进行依赖管理
If you prefer to use Ivy to manage dependencies then there are similar configuration options.
如果你喜欢使用lvy来进行依赖管理,那么也有类似的配置选项。
To configure Ivy to point to the Spring repository add the following resolver to your ivysettings.xml:
要配置lvy需要将一下的解析器添加到 ivysettings.xml
中来指向Spring库。
<resolvers> <ibiblio name="io.spring.repo.maven.release" m2compatible="true" root="http://repo.spring.io/release/"/></resolvers>
You can change the root URL from /release/ to /milestone/ or /snapshot/ as appropriate.
Once configured, you can add dependencies in the usual way. For example (in ivy.xml):
可以根据需要把root URL中的/release修改为/milestone或/snapshot。一旦仓库配置好了,就可以按lvy的方式声明依赖关系了
<dependency org="org.springframework"
name="spring-core" rev="5.0.0.BUILD-SNAPSHOT" conf="compile->runtime"/>
Distribution Zip Files
— zip发行版本
Although using a build system that supports dependency management is the recommended way to obtain the Spring Framework, it is still possible to download a distribution zip file.
尽管我们推荐使用构建系统来获取Sping Framework,但是我们也提供了Zip发行版。
Distribution zips are published to the Spring Maven Repository (this is just for our convenience, you don’t need Maven or any other build system in order to download them).
zip发行版本已经发布到了 Spring Maven库中了。
To download a distribution zip open a web browser to http://repo.spring.io/release/org/springframework/spring and select the appropriate subfolder for the version that you want. Distribution files end -dist.zip, for example spring-framework-{spring-version}-RELEASE-dist.zip. Distributions are also published for milestones and snapshots.
浏览器中打开http://repo.spring.io/release/org/springframework/spring ,根据版本选择相应的目录,发行版以-dist.zip
结束,例如 pring-framework-{spring-version}-RELEASE-dist.zip 。milestones 和 snapshots也有相应的zip发行本。
maven pom 示例
- Spring Dependencies and Depending on Spring
- IDEA Spring Model Dependencies
- Spring 依赖注入 (Dependencies)
- 使用JSF +Spring + Hibernate,Dependencies 总结
- spring-dependencies依赖项目jar下载地址
- spring学习2-Scoped beans as dependencies
- Install OpenCV dependencies on Ubuntu 16.04 with python2 and python3
- Conditionally include assemblies depending on Platform setting with MSBuild
- Join array elements depending on the element's index
- how to build your web application on spring boot and deploy it on heroku
- Pro Flex on Spring
- Spring depends-on
- Poems on Spring
- Spring depends-on
- Spring depends-on介绍
- Spring的 depends-on
- spring depends-on
- 【Java.Spring.Core】【IoC】Bean依赖注入- Dependencies
- 基于echars的图像绘制
- 深入hibernate的三种状态
- 使用Nexus搭建Maven私服
- SpringBoot四大神器之Starter
- 大数据生态体系介绍
- Spring Dependencies and Depending on Spring
- Java知识点总结(五)
- 安卓自定义透明Dialog
- tp5时间戳功能的自定义实现。
- C#基础之RichTextBox
- Mac上基于Xcode 8.3.2, iOS 10.3(模拟器)搭建Appium 1.6.5 测试环境
- SDE For PostgreSQL物理迁移(冷备份,恢复)
- Docker 命令
- JMeter压力测试post请求json参数来源文件