I’ve written two methods, findById searches for an item in the DB and throws an exception if the item is not found : The second method, findByShortUrl searches for an item in the DB and uses the JPA method findByShortUrlIs which returns a List of size 1 if the item is found, there should never be more t…
Tag: spring
Life span and injection of @SessionAttributes object in Spring MVC
I’m unclear on some subtleties of using @SessionAttributes in Spring MVC via Spring Boot 2.3.3.RELEASE. I have two controllers, Step1Controller and Step2Controller. Both controllers use @SessionAttributes(“foobar”) at the class level. Step1Controller during its request handling for @PostMapp…
Dynamic HTML in Thymeleaf
I am creating a Spring MVC + Thymeleaf project. I would like the user to have control over some parts of the page, meaning that user could change text and format is as well with colors, font sizes, etc., using HTML tags. However, I have not found any way how to insert dynamic HTML into thymleaf HTML template.…
Creating multiple beans of same type based on external config
I’m very, very new to Spring and have a bit of a complex thing to implement. I have an external configuration file that specifies how many of SomeDevice I will have, as well as what port each of SomeDevice will be listening on. An instance of SomeClass will be in charge of each SomeDevice. So I’ll…
Inject system environment variable into Spring Annotation with placeholder
I know you can inject environment variables with the @Value annotation like this If I am using a Spring annotation however can I inject the environment variable in-line into the String value? For example something like this: Obviously the above doesn’t work as it tries to resolve systemEnvironment[̵…
when there are some classes which may not exist, how should I manage them in an XxxAutoConfiguration?
com.example A // it provide AFactory.class 1 …
Concurrent requests transaction to prevent unwanted persistence
I am trying to get my head around how to approach what initially seems a “simple” problem. I have UserAccounts that can have MANY Purcahses BUT business logic dictates can only have one Purchase in a PurchaseState.IDLE state (a field on the entity). A purchase is IDLE when first created. I have a …
Consul Health indicator not showing in SpringBoot’ actuator health endpoint
I have a SpringBoot based web application that exposes a consul health indicator bean. The bean is correctly created and initialized by springboot’s autoconfiguration, yet, the indicator is not showing in the actuator health endpoint despite the fact that the associated configuration property “man…
JPA does not return default value after saving
I faced a problem. A have an entity: DDL of the related table: I have such logic: Field dateCreate is set by DB function now() but it is not returned by JPA in created entity. Does anyone know how to solve this problem? Without using Hibernate or Spring specific tools. Just JPA. Answer You need to refresh the…
Programmatically restart HikariPool in Spring Boot application?
I have a Spring Boot application which uses Hibernate, and HikariDataSource / HikariPool to talk to the database. A special feature in the app triggers database restart. Currently this breaks the connections in HikariPool: Old version of the app does call programmatically org.hibernate.SessionFactory.close();…