I am new to spring and I explore it using “Spring in action 5” book. I do similar actions with my website, I have written 2 controllers and 2 html files for pages. The first page is a form for pizza creation. the second is order submission. My code for controllers is practically the same as in the…
Tag: spring
Spring Boot URL mapping not working when files are present in multiple packages
I tried making a simple REST API using Spring Boot. I have put the classes in separate packages. In this case, the URL mapping is not working (checked using Postman), whereas its working fine if I put them all in the same package as that of the main class. “”” Hierarchy of the packages : com…
How to create immutable and singleton class in Spring boot?
I have a person model class that needs to be immutable and singleton. I need to autowire from my service class but getting an error. So is there any way to create a singleton immutable class in spring boot? where i can set values in person (via autowire) and use the same in the entire application. I have just…
How to check if a JWT Token has expired without throw exceptions?
I’m developing a Java application (using Spring Boot) and I need some help: This application receives as input a JWT token which I process in a method. The method for now is the following: } However, I need to implement a logic that must check in several places whether the token obtained has expired or …
Use value of a local variable as global in thymeleaf
I have a variable that is obtain inside each block in thymeleaf. I want to send that variable to a certain method in my controller. The limitation is that the variable is obtain inside a block which makes it local, not accessible global.Hence I get an error while trying to use it. How can I move inside the sc…
How adap Sleuth headers to make them compatible with OpenTracing
I’m working on a big stack of micro services written in Spring Boot, those services are using spring-cloud-starter-sleuth in order to trace the calls between several services. My concern is that I have implemented a new service based on Quarkus and the quarkus-smallrye-opentracing doesn’t recogniz…
Implement Search specification for pagination
I implemented this Page request: The question is how to implement search functionality for this Page request? I would like to send params like type and dateAdded into GET params and return filtered result? Answer There are two ways to achieve this: Examples. Simple but can only be used for simple searches To …
Cant run my spring application on ubuntu with jdk11
Pls, help. Can’t run my application on ubuntu 18.04.5 Java version: openjdk 11.0.10 2021-01-19 Apache Maven 3.6.0 Maven home: /usr/share/maven Java version: 11.0.10, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64 Default locale: en_US, platform encoding: UTF-8 OS name: “linux”, …
Can I choose to include/exclude what controller is deployed per environment in Spring Boot?
I would like to expose an endpoint only to certain TEST environment and leave it out altogether in PROD. I will have a separate @RestController for this endpoint. My question is how to ensure this endpoint is accessible only from the test env and never in production? I tried to play around with @ComponentScan…
Spring Jackson deserialize object with reference to existing object by Id
I have three entity classes of the following: Shipments Entity: Shipment Details Entity: Product Entity: I am receiving JSONs through a rest API. The problem is I do not know how to deserialize a new Shipment with shipmentDetails that have relationships to already existing objects just by ID. I know you can s…