I have application in Spring Boot. After initialization of Spring Boot with embeded tomcat, the first response is very slow. How can I fix it? Has spring boot any warmup command/mode? I am thinking too about connection with database and I am wondering about connection database, probably spring connects with Postgres during first request.
You could either use ApplicationRunner or CommandlineRunner to run something on startup:
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-command-line-runner
Related
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.
I have a non-web Spring Boot Library which has persistence entities that will be used by web application clients to communicate with the database. When I create my tests, I'm using #SpringBootTest in my spring integration tests, thus simulating a spring boot application using my library.
When setting the spring.h2.console.enabled to true, I thought I would be able to debug through my integration tests and have the H2 console enabled so that I can peer into the data by going to http://localhost:8080/h2-console, but the console doesn't load in my browser.
I have suspicions that this is somehow related to the fact that since my library is not a web-mvc library, it isn't auto configuring the H2 WebServlet, but I would like to know if providing the property would be enough for spring boot to auto configure the servlet.
Does anyone know if providing the H2 property would be enough? Or do I need to do something to enable the H2 WebServlet to be enabled?
I managed to get it working (somewhat) by adding a webEnvironment entry in the #SpringBootTest annotation. This allowed the H2 WebServlet to be registered. The reason that I said "somewhat" was because whenever I debug the test, the thread seems to suspend and I get very delayed response times from H2 when requesting it in my browser (http://localhost:8080/h2-console). My H2 database is very small (500 KB) so I would assume this has something to do with the server being embedded and tied to the test somehow?
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
I would like to ask how to refresh spring boot configuration info with using spring cloud config. Would you please give me some advice? Many thanks.
If your spring boot application is a client of Spring Cloud Configuration Server and use itself as single point of truth in the application configuration let's say retrieve application.properties/yml from the config server, you can benefit of #RefreshScope. in this case if you do a post to the /refresh if you use spring boot 1.x or /actuator/refresh if you use spring boot 2.x all the bean that are have are annotated as #RefreshScope will be refreshed.
When multiple spring boot applications created and deployed to a tomcat server. Is it possible to use a common connection pooling, datasource instead of providing these details in application.properties file. Or does this already taken care within the spring boot implementation
When you deploy multiple application then each application manages it connection pool.
Spring boot boundary is limited to each application context and it does not know what other application deployed and which db they are using.