Getting Dependencies without Spring Boot

当把Spring用于Apache Pulsar时,我们推荐先采取Spring Boot方法。不过,如果您不使用Spring Boot,获取依赖关系的首选方法是使用提供的BOM,以确保在整个项目中使用模块的统一版本。以下示例展示了在Maven和Gradle中如何执行此操作:

We recommend a Spring Boot first approach when using Spring for Apache Pulsar. However, if you do not use Spring Boot, the preferred way to get the dependencies is to use the provided BOM to ensure a consistent version of modules is used throughout your entire project. The following example shows how to do so for both Maven and Gradle:

  • Maven

  • Gradle

pom.xml
<dependencyManagement>
	<dependencies>
		<!-- ... other dependency elements ... -->
		<dependency>
			<groupId>org.springframework.pulsar</groupId>
			<artifactId>spring-pulsar-bom</artifactId>
			<version>{spring-pulsar-version}</version>
			<type>pom</type>
			<scope>import</scope>
		</dependency>
	</dependencies>
</dependencyManagement>
build.gradle
plugins {
	id "io.spring.dependency-management" version "1.1.4"
}

dependencyManagement {
	imports {
		mavenBom 'org.springframework.pulsar:spring-pulsar-bom:{spring-pulsar-version}'
	}
}

一个最小的Spring用于Apache Pulsar依赖关系集通常看起来像这样:

A minimal Spring for Apache Pulsar set of dependencies typically looks like the following:

  • Maven

  • Gradle

pom.xml
<dependencies>
	<!-- ... other dependency elements ... -->
	<dependency>
		<groupId>org.springframework.pulsar</groupId>
		<artifactId>spring-pulsar</artifactId>
	</dependency>
</dependencies>
build.gradle
dependencies {
	implementation "org.springframework.pulsar:spring-pulsar"
}

如果您使用的是附加功能(如 Reactive),则还需要包含相应的依赖项。

If you use additional features (such as Reactive), you need to also include the appropriate dependencies.

Spring for Apache Pulsar 针对 Spring Framework {spring-framework-version} 构建,但通常应该使用任何较新的 Spring Framework 6.x 版本。很多用户可能会遇到 Spring for Apache Pulsar 的传递依赖项解析了 Spring Framework {spring-framework-version} 的事实,这会导致奇怪的类路径问题。解决此问题最简单的方法是在 dependencyManagement 部分中使用 spring-framework-bom,如下所示:

Spring for Apache Pulsar builds against Spring Framework {spring-framework-version} but should generally work with any newer version of Spring Framework 6.x. Many users are likely to run afoul of the fact that Spring for Apache Pulsar’s transitive dependencies resolve Spring Framework {spring-framework-version}, which can cause strange classpath problems. The easiest way to resolve this is to use the spring-framework-bom within your dependencyManagement section as follows:

  • Maven

  • Gradle

pom.xml
<dependencyManagement>
	<dependencies>
		<!-- ... other dependency elements ... -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-framework-bom</artifactId>
			<version>{spring-framework-version}</version>
			<type>pom</type>
			<scope>import</scope>
		</dependency>
	</dependencies>
</dependencyManagement>
build.gradle
plugins {
	id "io.spring.dependency-management" version "1.1.4"
}

dependencyManagement {
	imports {
		mavenBom 'org.springframework:spring-framework-bom:{spring-framework-version}'
	}
}

前面的示例确保了 Spring for Apache Pulsar 的所有传递依赖项都使用 Spring {spring-framework-version} 模块。

The preceding example ensures that all the transitive dependencies of Spring for Apache Pulsar use the Spring {spring-framework-version} modules.