ServerRequest on SpringBoot 2.0.0.RELEASE - spring

I recently moved my app. from Spring Boot 1 to Spring Boot 2 (2.0.0.RELEASE).
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
I want to import the class org.springframework.web.reactive.function.server.ServerRequest to get the Error Attributes from the interface
org.springframework.boot.web.reactive.error.ErrorAttributes;
but I got this error:
The import org.springframework.web.reactive.function.server.ServerRequest cannot be resolved

The Spring Boot Reactive Project spring-boot-web-reactive was merged into Spring Webflux with Spring 5.0
Make sure you have webflux Starter on your classpath:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webflux</artifactId>
</dependency>

Related

how to import spring-boot-starter-data-solr in spring boot 2.6.4

I'm studying using solr in springboot, I try the program in a book, the spring-boot-starter-parent version is 2.1.2.RELEASE in the book:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
while my spring-boot-starter-parent version is 2.6.4:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
and I add the solr dependency in pom.xml like this:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
</dependency>
but the pom.xml shows error: The version cannot be empty, so I go to https://mvnrepository.com/ and find the latest spring-boot-starter-data-solr version is 2.4.13, so I add the solr dependcy like this:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
<version>2.4.13</version>
</dependency>
the pom.xml has no error now, but the java program which import solr still not work, such as:
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
it cannot find any class about solr. I also try to download the spring-boot-starter-data-solr jar in https://mvnrepository.com/, and I import it locally, but I only find a META-INF document in the spring-boot-starter-data-solr jar downloaded, it doesn't have any classes
so how should I use solr in springboot?
The Spring Data for Apache Solr project has been discontinued. As a result, it was removed from the Spring Data release train in its 2021.0.0 release and from Spring Boot in its 2.5.0 release.
If you are using Solr directly, rather than via Spring Data, you can continue to do so. You will have to declare your Solr dependencies directly rather than relying on the Data Solr starter and you will have to configure Solr in your application rather than relying on Spring Boot's auto-configuration to do so.
solr-solrj is probably the updated alternative to the not updated spring-data-solr.

spring-boot-starter-parent AND spring version

I'm developing a Java spring web service application. The application has a maven multi module layout, containing a webapp module - and a client module with a retrofit client.
I want to use the spring boot starter to manage my dependencies - and thus my webapp has the entry:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
</parent>
My client needs some Spring types - and this dependency would suufice:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.4.RELEASE</version>
</dependency>
Is there anyway to couple these versions?
You can use Spring Boot without the parent.
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using-boot-maven-without-a-parent
So you could add the dependency management to your own parent POM and both modules can use that as parent.

How to use Spring Kafka 2.1.0.RELEASE

It is really great to grab the Spring Kafka 2.1.0.RELEASE to unleash the power of the kafka client 1.0.0. However when I tried to use it spring boot 1.5.9.RELEASE , which is the latest release version of boot it throws an exception .
java.lang.NoSuchMethodError: org.springframework.util.Assert.state(ZLjava/util/function/Supplier;)V
at org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter.determineInferredType(MessagingMessageListenerAdapter.java:396) ~[spring-kafka-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter.<init>(MessagingMessageListenerAdapter.java:100) ~[spring-kafka-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.kafka.listener.adapter.RecordMessagingMessageListenerAdapter.<init>(RecordMessagingMessageListenerAdapter.java:61) ~[spring-kafka-2.1.0.RELEASE.jar:2.1.0.RELEASE]
My POM file is
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath />
</parent>
...
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<version>2.1.0.RELEASE</version>
<scope>test</scope>
</dependency>
.....
How should I be able to use Spring Kafka 2.1.0.RELEASE with a spring boot project .
Is there any release of boot that support spring 5 yet.
Thanks
Joy
For the Answer
Click disqus.com
This is beautifully explained by Francisco , I put up the link as it might help others as well!
I am using Spring boot 1.5.9.RELEASE and spring-kafka:2.1.0.RELEASE have faced similar but not this exception, I would suggest cleaning and building application again to clear maven cache and dependencies.

ClassNotFoundException with Spring WebFlux Security

I'm having the following problem:
I am trying to setup a basic Spring Boot (2.0.0.M2) Project containing Spring Webflux and Spring Security.
My pom.xml looks like this (generated via start.spring.io):
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.M2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
...
</dependencies>
SpringSecurityConfig:
#EnableWebFluxSecurity
public class SecurityConfig extends WebFluxSecurityConfiguration {}
I am not getting any further because I get an exception on startup:
Caused by: java.lang.ClassNotFoundException: org.springframework.security.web.server.context.SecurityContextRepository
So I figure that the whole org.springframework.security.web.server package is not on the classpath, although it should be there, since it is included in the API docs.
Seems like I am doing something wrong, but I don't know what.
Currently Spring Boot's spring-boot-starter-security does not include spring-security-webflux.
Add it as project dependency explicitly.
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-webflux</artifactId>
</dependency>
See this issue : Provide auto-configuration for WebFlux-based security.
BTW, check my working codes: https://github.com/hantsy/spring-reactive-sample/tree/master/boot
Updated: In Spring Boot 2.0.0.RELEASE, spring-boot-starter-security includes webflux support.

Spring Boot minimum version requirement for Spring Cloud Contract to work ?

I'm using latest Spring Boot 1.3 in my client app and I would like to introduce Spring Cloud Contract :
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.8.RELEASE</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
I'm able to generate stubs from the producer side, but from consumer side, I'm not able to adapt the example given on https://cloud.spring.io/spring-cloud-contract/ .
I'm replacing the test runner SpringRunner (not available with Spring Boot 1.3) by SpringJUnit4ClassRunner, but the #AutoConfigureStubRunner annotation seems to be ignored.
I don't see any requirement on Spring Boot version mentioned in Spring Cloud Contract page : is there any ?
From my experience, it seems Spring Boot 1.4+ is required. After upgrading to
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
I see #AutoConfigureStubRunner is taken into account.

Resources