没有Spring Boot如何获得依赖

我们建议在使用 Apache Pulsar 时先使用 Spring Boot 方法。 不过,如果你不使用 Spring Boot,获取依赖的首选方式是使用提供的物料清单,以确保整个项目中使用的模块版本一致。 以下示例展示了如何为Maven和Gradle实现:spring-doc.cadn.net.cn

pom.xml
<dependencyManagement>
	<dependencies>
		<!-- ... other dependency elements ... -->
		<dependency>
			<groupId>org.springframework.pulsar</groupId>
			<artifactId>spring-pulsar-bom</artifactId>
			<version>1.2.13-SNAPSHOT</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:1.2.13-SNAPSHOT'
	}
}

Apache Pulsar 的最小 Spring 依赖集合通常如下:spring-doc.cadn.net.cn

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"
}

如果你使用额外功能(如响应式),还需要包含相应的依赖关系。spring-doc.cadn.net.cn

Spring for Apache Pulsar 基于 Spring Framework 6.2.14 构建,但通常可以兼容任何更新版本的 Spring Framework 6.x。 许多用户可能会遇到 Spring for Apache Pulsar 的传递依赖关系解决 Spring Framework 6.2.14 的事实,这可能导致奇怪的类路径问题。 解决这个问题最简单的方法是使用Spring-框架-BOM在你的依赖管理部分如下:spring-doc.cadn.net.cn

pom.xml
<dependencyManagement>
	<dependencies>
		<!-- ... other dependency elements ... -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-framework-bom</artifactId>
			<version>6.2.14</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:6.2.14'
	}
}

前述示例确保 Spring for Apache Pulsar 的所有传递依赖都使用 Spring 6.2.14 模块。spring-doc.cadn.net.cn