Can I use Redis Cache with spring only - spring

I have an existing apllication with spring version below:
<spring.version>4.2.3.RELEASE</spring.version>
All the examples I found are with springboot.
When I added springboot dependency for redis as below:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.4.3</version>
</dependency>
On compilation it gives the below error
java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: org/springframework/util/unit/DataSize
Can I use redis cache without spring boot and with spring core.

Related

java.lang.NoClassDefFoundError: Could not initialize class org.springframework.web.reactive.function.client.DefaultExchangeStrategiesBuilder

I am trying to use spring WebClient wc = WebClient.create(); in a non-Spring application, but it looks like DefaultExchangeStrategiesBuilder.DEFAULT_EXCHANGE_STRATEGIES returns null
causing error:
java.lang.NoClassDefFoundError: Could not initialize class org.springframework.web.reactive.function.client.DefaultExchangeStrategiesBuilder
at org.springframework.web.reactive.function.client.ExchangeStrategies.withDefaults(ExchangeStrategies.java:67)
at org.springframework.web.reactive.function.client.DefaultWebClientBuilder.initExchangeStrategies(DefaultWebClientBuilder.java:302)
at org.springframework.web.reactive.function.client.DefaultWebClientBuilder.build(DefaultWebClientBuilder.java:269)
at org.springframework.web.reactive.function.client.WebClient.create(WebClient.java:144)
I have added to my POM:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>2.6.5</version>
</dependency>
If your application is not a Spring Boot application and does not apply Spring Boot's dependency management, you should not use Spring Boot's starters.
Instead you should use Spring Framework's spring-webflux dependency directly, as well as a client library of your choice, like Reactor Netty, Jetty client, Apache HttpComponents...
You should also ensure that the Spring Framework BOM is applied to your project to avoid an incompatible mix of versions in your application:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>...</version>
<type>pom</type>
</dependency>

Spring initializr not showing activiti dependency

I am trying to create spring-boot project for activiti but it is not showing activiti dependency.
How can I know that with which springboot version,activiti version is mapped?
Spring Initializr
If you're refererring to Activiti, this is not included in the Spring Initializr so you will need to include this manually yourself.
Go through the Spring Initializr setup
Generate and download the code to your machine
Add the Activiti dependency to your POM or Gradle file:
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>6.0.0</version>
</dependency>
Add the H2 dependency for database (don't use this in production):
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.183</version>
</dependency>
I haven't used Activiti before but this is based on their Spring Boot documentation.
Spring boot 2 doesn't have activiti anymore.
Manually need to add activiti dependency.
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter</artifactId>
<version>7.0.0.Beta1</version>
</dependency>

Problem in configuring spring boot and redis

I have an old spring boot application (1.5.0-FINAL) and I can't change this version.
I want to add redis to my application, that's what I did:
1) added the maven dep:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>1.5.10.RELEASE</version>
</dependency>
2) Added the property to my boot
#EnableCaching
public class MySpringBootApp{
3) Added config properties to check if it starts the connection:
spring.cache.type: redis
spring.redis.host: 192.168.99.100
spring.redis.port: 6379
The host/port above do not exist: I just want to see something like "connection error" on boot to make sure I configured everything but nothing appears! It seems that spring boot just doesn't try to use a cache.
Am I missing something?Maybe my spring boot version is too old?
Spring Boot parent pom already defines the versions of the starters, so remove the version from spring-boot-starter-data-redis dependency.
Your pom.xml would have at least these dependencies.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
Next, #EnableCaching will look for beans with #Cacheable or #CachePut annotations.

My Jersey Spring Boot 1.5.2 project doesn't recognize FormDataMultiPart

I tried to add FormDataMultiPart to my Jersey Spring Boot project. I am using Spring Boot 1.5.2 and the Spring Boot Jersey Starter.
I tried adding the full import org.glassfish.jersey.media.multipart.FormDataMultiPart, but it is not found.
It looks like spring-boot-starter-jersey Maven dependency does not include jersey-media-multipart. You need to add it to your pom.xml. On the other hand, Spring Boot does define a jersey.version property so you can use that to keep the versions in sync.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<!-- Multipart not included in Spring Boot. jersey.version defined by Spring Boot. -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>${jersey.version}</version>
</dependency>
Once you add the jersey-media-multipart dependency to Maven, the FormDataMultiPart class can be found.

Difference between the jars for spring web services

I have just started learning on spring webservices but when I search for the tutorials in some examples they added the following dependency for springwscore and in some examples the following dependency for spring-boot-starter-ws.which jar sholud be used and why spring has two jars for spring web services.
The easiest way would be including dependency by adding Spring Ws Core to Maven pom.xml file (if you are using Maven)
<dependencies>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>2.4.0.RELEASE</version>
</dependency>
</dependencies>

Resources