How can I use Spring Cloud OpenFeign with Spring Boot 3.0.0-M4? - spring-boot

I want to use Spring Cloud OpenFeign with Spring Boot 3.0.0-M4 But I could not find the compatible version of Spring Cloud OpenFeign with spring boot 3.0.0-M4.
for using OpenFeign with this version of spring boot what should I do?

The new Spring Boot milestone version 3.0.0-M5 got released end of September.
You can use the corresponding Spring Cloud version 2022.0.0-M5 which includes Spring Cloud Openfeign 4.0.0-M5.
See https://spring.io/blog/2022/10/06/spring-cloud-2022-0-0-m5-is-now-available
(The same most probably works with M4 if you really have to use it)
However I would advise on using https://start.spring.io to generate your project stub and maven or gradle files that take care of selecting the correct versions for Spring Cloud modules like Openfeign.
Shortened example for build.gradle:
plugins {
id 'org.springframework.boot' version '3.0.0-M5'
id 'io.spring.dependency-management' version '1.0.14.RELEASE'
id 'java'
}
sourceCompatibility = '17'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}
ext {
set('springCloudVersion', "2022.0.0-M5")
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}

Related

getting Spring Boot [2.7.0] is not compatible with this Spring Cloud release train error

I am new to spring.
I was trying to upgrade spring boot version from 2.3.3.RELEASE to 2.6.7 in existing spring batch project.
Project build completed successfully but I am getting bellow error when I run batch. Please help.
***************************
APPLICATION FAILED TO START
***************************
Description:
Your project setup is incompatible with our requirements due to following reasons:
- Spring Boot [2.6.7] is not compatible with this Spring Cloud release train
Action:
Consider applying the following actions:
- Change Spring Boot version to one of the following versions [2.3.x, 2.4.x] .
You can find the latest Spring Boot versions here [https://spring.io/projects/spring-boot#learn].
If you want to learn more about the Spring Cloud Release train compatibility, you can visit this page [https://spring.io/projects/spring-cloud#overview] and check the [Release Trains] section.
If you want to disable this check, just set the property [spring.cloud.compatibility-verifier.enabled=false]
My current code of build.gradle is as below,
buildscript {
ext {
springBootVersion = '2.6.7'
}
}
plugins {
id 'org.springframework.boot' version "${springBootVersion}"
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = 11
tasks.named("bootJar") {
archiveFileName = "${archiveBaseName.get()}.${archiveExtension.get()}"
mainClass = 'jp.co.BatchApplication'
}
jar.archiveFileName = bootJar.archiveFileName
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-batch:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-thymeleaf:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-aop:${springBootVersion}")
implementation("org.springframework.retry:spring-retry:1.2.5.RELEASE")
implementation("org.projectlombok:lombok:1.18.24")
annotationProcessor("org.projectlombok:lombok:1.18.24")
implementation('mysql:mysql-connector-java:8.0.17')
implementation('org.seasar.doma.boot:doma-spring-boot-starter:1.4.0')
annotationProcessor('org.seasar.doma:doma-processor:2.35.0')
implementation('org.apache.commons:commons-lang3:3.11')
implementation('org.apache.commons:commons-collections4:4.4')
implementation('com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.2')
implementation("javax.xml.bind:jaxb-api:2.3.1")
implementation(fileTree(dir: 'lib', include: ['*.jar']))
implementation("org.hibernate.validator:hibernate-validator:6.1.5.Final")
implementation('org.apache.httpcomponents:httpclient:4.5.12')
// for r3-id-1.0.1.jar
implementation('commons-digester:commons-digester:2.1')
// Azure App Configuration
implementation('com.microsoft.azure:spring-cloud-azure-appconfiguration-config-web:1.3.0')
implementation('com.microsoft.azure:spring-cloud-azure-feature-management-web:1.3.0')
testImplementation("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
}
*
*
*
*
I guess it is not relevant to this error but I have also change DefaultBatchConfigurer class from use of MapJobRepositoryFactoryBean to JobRepositoryFactoryBean. As MapJobRepositoryFactoryBean is deprecated.
The error is quite explanatory ...
- Spring Boot [2.6.7] is not compatible with this Spring Cloud release train
Spring Cloud versions are tied to specific Spring Boot versions. When using Spring Cloud you cannot just upgrade Spring Boot you also need to upgrade Spring Cloud to a version that supports that Spring Boot version.
As you are using some Azure Cloud dependencies you need to upgrade those to a newer version (if available) that support a Spring Cloud version that supports Spring Boot 2.6.
Pro Tip I would also suggest to cleanup your dependencies so you benefit, more, from the Spring Boot dependency management
dependencies {
implementation("org.springframework.boot:spring-boot-starter-batch")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
implementation("org.springframework.boot:spring-boot-starter-aop")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.retry:spring-retry")
implementation("org.projectlombok:lombok")
annotationProcessor("org.projectlombok:lombok")
implementation('mysql:mysql-connector-java')
implementation('org.seasar.doma.boot:doma-spring-boot-starter:1.4.0')
annotationProcessor('org.seasar.doma:doma-processor:2.35.0')
implementation('org.apache.commons:commons-lang3:3.11')
implementation('org.apache.commons:commons-collections4:4.4')
implementation('com.fasterxml.jackson.dataformat:jackson-dataformat-xml')
implementation("javax.xml.bind:jaxb-api")
// for Mu Client
implementation(fileTree(dir: 'lib', include: ['*.jar']))
implementation('org.apache.httpcomponents:httpclient')
// for r3-id-3.0.1.jar
implementation('commons-digester:commons-digester:2.1')
// Azure App Configuration
implementation('com.microsoft.azure:spring-cloud-azure-appconfiguration-config-web:1.3.0')
implementation('com.microsoft.azure:spring-cloud-azure-feature-management-web:1.3.0')
testImplementation("org.springframework.boot:spring-boot-starter-test")
}

How to use spring boot in gradle without the spring boot gradle plugin

Can anyone show me or point me to a spring boot gradle project that does not make use of the spring boot gradle plugin.
I'm looking for something like a spring boot starter web hello world example that doesn't use the gradle plugin.
I can't imagine that the plugin is a requirement, but a search for examples all seem to lean on the gradle plugin, which lets just say is not an option in my environment, and no I can't switch to maven either.
Ideally the gradle build would work by adding something like the following:
gradle.properties
springBootVersion=2.1.3.RELEASE
build.gradle
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion
}
I used the spring dependency management plugin, and it works
buildscript {
ext {
springDepManagementVersion = '1.0.10.RELEASE'
springBootVersion = '2.6.6'
springCloudVersion = "2021.0.1"
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:${springDepManagementVersion}"
}
}
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
}
}
dependencies {
implementation "org.springframework.cloud:spring-cloud-starter-sleuth"
implementation 'org.springframework.boot:spring-boot-starter-json'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-security'
...
}
I can't use spring boot gradle plugin, since I can only use gradle 6.7.1, while spring boot gradle plugin requires gradle version at least 6.8 to support spring boot 2.6. I was inspired by the spring cloud bom solution.

Building a Spring-boot project without eclipse gradle

I'm fairly new to gradle and writing a project that I have working in eclipse and was posed with the challenge to write it without eclipse using gradle. I'm finding that even once I add the spring framework configurations to my build file it still can not see what I am importing. I am also using maven so I think it my understanding of gradle changing from a maven project and with SQL. Any thoughts?
Here is my build.gradle:
plugins {
id "org.springframework.boot" version "1.5.9.RELEASE"
id "io.spring.dependency-management" version "1.0.4.RELEASE"
}
apply plugin: 'java'
repositories {
jcenter()
mavenCentral()
}
// spring dependency management plugin configuration
dependencyManagement {
imports {
// select versions based on this BOM
mavenBom 'io.spring.platform:platform-bom:1.1.1.RELEASE'
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile("org.springframework:spring-jdbc")
compile('mysql:mysql-connector-java:5.1.37')
}
You need to add spring boot dependencies.
like:
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
}
See the Spring documentation:
https://spring.io/guides/gs/spring-boot/#scratch

Why does Neo4j OGM with Spring Boot 2.0.0.M4 apparently require the embedded driver?

I have been trialling Spring Boot 2 (2.0.0.M4 at this stage) with the latest Spring Data Neo4j (currently 5.0.0.RC3) and can't seem to get it running.
I get the following error:
org.neo4j.ogm.exception.ConfigurationException: Could not load driver class org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver
I don't ask for an embedded driver, nor do I want one. I only want to use the bolt driver, which is already a dependency of spring-data-neo4j.
I've published a project to Github that was built using output from Spring Initializr that can be run to expose the error.
For reference, my build.gradle is as follows. Am I mis-configuring my project? Or is there something more serious wrong with the current Spring and Neo4j milestone builds?
buildscript {
ext {
springBootVersion = '2.0.0.M4'
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
version = "0.0.1-SNAPSHOT"
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile "org.apache.tomcat.embed:tomcat-embed-jasper"
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.boot:spring-boot-starter-data-neo4j"
runtime "org.springframework.boot:spring-boot-devtools"
}
The rest of the code is available in Github as I mentioned earlier.
You don't have the embedded driver dependency anywhere, see
./gradlew dependencies
output and search for neo4j-ogm.*driver - only neo4j-ogm-bolt driver is present. So if you want to use bolt only you have the dependencies set up correctly.
The reason why you see this exception is because you configuration is wrong:
return new SessionFactory("com.example.domain");
This doesn't provide path to configuration file, the default then is impermanent embedded database, which needs the embedded driver - hence the exception.
You have two options
pass OGM configuration to SessionFactory:
#Bean
public org.neo4j.ogm.config.Configuration configuration() {
return new org.neo4j.ogm.config.Configuration.Builder(new ClasspathConfigurationSource("ogm.properties")).build();
}
#Bean
public SessionFactory sessionFactory() {
return new SessionFactory(configuration(), "com.example.domain");
}
beware that this is OGM only solution and doesn't support yml files.
use spring boot auto configuration for SDN - just delete the Neo4jConfiguration class, Spring Boot will detect there is no SessionFactory bean and will configure all required (including transaction manager). Keep your Application class and application.yml as it is.

How are some gradle dependencies working with no version supplied

As far as I know gradle requires a version number when setting dependencies, but partial wildcards are allowed. For example if I want Guava, I cannot do this as it fails:
compile('com.google.guava:guava')
It has to be (as an example):
compile('com.google.guava:guava:21.0')
However, I'm learning Spring, which has the following:
compile("org.springframework.boot:spring-boot-starter")
compile("org.springframework:spring-web")
compile("com.fasterxml.jackson.core:jackson-databind")
How are these dependencies working with no version supplied?
Is it because of the following, but I thought these lines were required only for my plugin 'org.springframework.boot':
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.3.RELEASE")
}
}
It is worth mentioning that the trick is called BOM (bill of materials) and the actual versions can be checked in the related POM file (in this example, it is for the version 2.7.0) inside spring-boot-dependencies package. This is mentioned in the Spring Boot official documentation here: Build Systems.
Another way that Spring provides this (for non Boot projects) is through Spring Platform BOM where it actually provides version for the following dependencies.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'io.spring.gradle:dependency-management-plugin:0.6.0.RELEASE'
}
}
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:Athens-SR2'
}
}
TL;DR - spring boot uses custom dependencies resolver.
A spring boot plugin that is applied with the following piece of code:
apply plugin: 'spring-boot'
handles the dependencies that are listed without version. This logic is implemented in this class which delegates it to here. DependencyManagementPluginFeatures are applied here.
The spring boot gradle plugin documentation states the following:
The version of the spring-boot gradle plugin that you declare
determines the version of the spring-boot-starter-parent bom that is
imported (this ensures that builds are always repeatable). You should
always set the version of the spring-boot gradle plugin to the actual
Spring Boot version that you wish to use.
Spring Boot Dependency Management Plugin is not necessary.
You may use build-in Gradle BOM support instead of Spring Boot Dependency Management Plugin
For example:
plugins {
id 'java'
id 'org.springframework.boot' version '2.1.0.RELEASE'
}
repositories {
jcenter()
}
dependencies {
implementation platform('org.springframework.boot:spring-boot-dependencies:2.1.0.RELEASE')
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'
}
and for multi-module project:
in root build.gradle :
plugins {
id 'java-library'
id 'org.springframework.boot' version '2.1.0.RELEASE'
}
allprojects {
apply plugin: 'java-library'
repositories {
jcenter()
}
}
dependencies {
implementation project(':core')
implementation 'org.springframework.boot:spring-boot-starter-web'
}
and in core/build.gradle
dependencies {
api platform('org.springframework.boot:spring-boot-dependencies:2.1.0.RELEASE')
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

Resources