Spring Redis Cache - spring

New to Spring, have an old Spring Project, NOT Spring Boot
Need to implement in memory cache using Redis,
Following this guide - https://www.baeldung.com/spring-setting-ttl-value-cache
To start with, added just only bellow two dependency
implementation("org.springframework.boot:spring-boot-starter-cache:2.7.5")
implementation("org.springframework.boot:spring-boot-starter-data-redis:2.7.5")
When I start the application after compilation, I am getting -
Caused by: java.lang.NoClassDefFoundError: org/springframework/core/metrics/ApplicationStartUp
Could not find an example of Redis Cache only for Spring (all are for Spring Boot).
Need to implement Redis Cache on Spring only, NOT on Spring Boot.

Related

How to create Springboot App with postgres using spring native graalvm?

I was trying to create a CRUD app using spring boot and postgres ,alongwith spring native.But I couldn't find any proper documentation related to it apart from spring native documentation.
The part of how to integrate it with postgres,is what I am looking for.Thankyou
You can use Spring Data like you would in a standard Spring Boot application. Depending on the type of application, you can use Spring Data JDBC, Spring Data JPA (if you need the Hibernate features), or Spring Data R2DBC (for reactive apps). If you bootstrap your application from start.spring.io, you can directly select the PostgreSQL dependency from there.
To get started with Spring Data, you can refer to this guide on the Spring website: relational data access with Spring Data JDBC. It uses H2, but you can replace it with PostgreSQL. More details are available on the project documentation.
On my GitHub, you can find an example of Spring Boot application with a REST API, security, and data persistence with PostgreSQL. And packaged as a native executable through Spring Native. If you're new to Spring Native, I wrote an article about how to get started with it.

Avoid Spring Boot App to connect to Cassandra on boot

I have a Spring Boot Application which stores/retries data from Cassandra DB. But if Cassandra is not available, Spring application does not boot.
Here is my code - https://github.com/simplyatul/springcassandrajunit
I am playing around DemoTableRepo.java. If I comment out
#RepositoryDefinition(domainClass = DemoTable.class, idClass = String.class)
then Spring boot app starts w/o connecting to Cassandra, however when Repo is used on retrieve/store call it throws following exception
java.lang.IllegalArgumentException: Interface org.simplyatul.cassandrajunit.repository.DemoTableRepo must be annotated with #org.springframework.data.repository.RepositoryDefinition!
If I keep the following line commented
#RepositoryDefinition(domainClass = DemoTable.class, idClass = String.class)
then Spring boot app tries to connect to Cassandra on boot and fails to start.
I found similar links/Qs, but things are not working with the solutions provided. Am I missing anything? Thanks in advance.
How can we stop spring boot data cassandra from connecting to localhost?
How to load spring application context even if Cassandra down

Spring Cloud Data Flow - can it be used without spring boot?

Can Spring Cloud Data Flow be used in Spring5 applications - NOT Spring Boot - my current employer seems to view Spring Boot applications as insecure (I've no idea why) in anyway I'd like to try use this stack for an integration project, so is it possible to use it without Spring Boot?
With Spring Cloud Data Flow you can deploy streams, tasks and batches.
This is all based on Spring, Spring Cloud and Spring Boot. Spring Boot is nothing else as a preconfigured Spring stack.
Spring Data Flow is a runitme that usually needs a cloud infrastructure like Kubernets.
I'm not sure if you really are looking for that or more for something like https://spring.io/projects/spring-integration

Spring Framework application high memory usage on start up

I have wrote REST APIs in java Spring Framework.
I have referred this github project and my project structure is very similar to this.
My application contains Spring Boot, Spring Security, Spring Security OAuth, Spring Data JPA and Spring mongodb.
I have observed that on start, the application consumes more than 100MB and increases 2MB on each URL request. Also mongodb connection is not closed automatically after some timeout.
I am not able to figure out this application start up memory usage. (is this because of spring boot or spring security or any other lib ?)
Is there any other best java framework for quick REST API development with Security, OAuth and MongoDB feature.
I want memory optimized REST APIs.

Spring boot application having second datasource failing caching

The presence of a second datasource in a spring boot application is failing caching with the exception:
java.lang.IllegalArgumentException: Cannot find cache named 'entity-name' for CacheEvictOperation
With one datasource it's working.
Both the datasource is auto-configured by spring boot.
Datasource one using mysql, declared as primary
Datasource two using mongodb
Is this a known case? Do I need to explicitly configure entity and transaction managers?
Spring Boot does not support auto-configuring more than one datasources for general purposes so you may want to revisit your configuration (or the description).
Yes, you need to configure the entity manager and transaction managers explicitly when you need to use more than one datasource.
Hopefully, this sample shows you how to do it.

Resources