I have different JSON files and need to read, process and write the containing JSON objects of a JSON array. The output format (more specific: the output class) is for all files the same. Lets call it OutputClass. Hence the item processor is something like ItemProcessor<X, OutPutClass>. Where X is the c…
Tag: spring
Null repository even with @Autowired implemented
I have the following controller. The following line works just fine: user = userRepository.selectUserByLogin(name); It correctly returns the user. Now I want to move that code to a getLoggedUser method of a “Utilities” class. This is how I did it. Controller Utilities But when that is executed I&#…
I have created a spring boot with DTO, Entity and also not able to store it
I have created a spring boot with DTO, Entity and also generating entity from dto and vice versa but the data is not getting stored in the Postgres sql when i am trying to get the data its is showing null but creation is happing First is the controller class Now the StudentDetailDto class now the StudenDto cl…
Is there a way to extend the Spring Actuator logger and invoke it from my own controller?
Is there a way to extend the Spring Actuator logger and invoke it from my own controller, so that I can do some security validations? For example, something like this: Answer You can secure the endpoint using Spring Security. See Securing HTTP Endpoints. If Spring Security is not an option and you do want to …
Spring MVC – JSP files for various controllers to be more generic
I have a java spring MVC project with various controllers. These controllers have the functionality to add, edit, delete configurations. The JSP files for these various controllers are almost same (…
Disable Spring Boot Webclient logs
I want to build a simple Spring Web Client who send message from stdin but the WebClient show all debug informations on stdout. How to disable the logs generated by Webclient ? Code of the client Answer you can customize your logs as you want. as the image you mention, Go to the application.properties put log…
Why do MockMvc tests suggest injecting WebApplicationContext @BeforeEach test?
So the reference documentation suggests why not do it as constructor injection instead? (I haven’t tried this, I’m just assuming it doesn’t immediately blow up) Answer Whether you choose constructor injection, method injection, or field injection is a matter of taste when using JUnit Jupiter…
How to solve this Problem: Error creating bean?
I am getting the following error and I am getting frustrated btw. Please help. This is the Error I am getting: This is my User Entity: This is my UserRepository: And this is my UserController: How can I solve this problem? Let me know if you need more. Answer You should remove prefix: “users_” for…
Restrict string data type to only string types for request body in Spring boot 2.4 (Jackson)
I have created my request POJO as follows when I send request body as follow, it is working fine. But when I sent like below Here is my controller Expected: throw some error Actual: converting true value for userId to string by jackson. please let me know is there a way to acheive the Expected behaviour Answe…
How to raise a ConstraintValidationException in a test case for bean properties with validation annotations?
I’m trying to test that my beans have correct validation annotations. I’m using spring-boot. Here is an example test case: I expect the call to checkIfvalidated() and to setSomeProperty(null) to raise a ConstraintViolationException, and the tests to pass, but they both fail with: My pom.xml: Why i…