Home » Spring

Tag Archives: Spring

Spring Web MVC

spring-interview-questions-answers

Spring MVC is a web framework based on the model–view–controller pattern. It is based on the Spring principles and supports a wide range of server-side rendering technologies as JSP, Thymeleaf, Groovy, among others. Dispatcher Servlet It is a front controller that coordinates all the request handling activities. Delegates to the web infrastructure beans and invokes the user’s web components. It ...

Read More »

Code Generation in CUBA: What makes the magic

Introduction Code generation is a common thing in modern frameworks. There may be different reasons behind introducing code generation – from getting rid of boilerplate code to reflection replacement and creating complex solutions based on domain-specific languages. Like every technology, code generation has application areas and limitations. In this article, we will have a look at code generation usage in ...

Read More »

Improving Spring Mock-MVC tests

java-interview-questions-answers

Spring Mock-MVC can be a great way to test Spring Boot REST APIs. Mock-MVC allows us to test Spring-MVC request handling without running a real server. I used Mock-MVC tests in various projects and in my experience they often become quite verbose. This doesn’t have to be bad. However, it often results in copy/pasting code snippets around in test classes. ...

Read More »

For gourmets and practioners: pick your flavour of the reactive stack with JAX-RS and Apache CXF

java-interview-questions-answers

When JAX-RS 2.1 specification was released back in 2017, one of its true novelties was the introduction of the reactive API extensions. The industry has acknowledged the importance of the modern programming paradigms and specification essentially mandated the first-class support of the asynchronous and reactive programming for the Client API. But what about the server side? It was not left ...

Read More »

Reduce Repetitive Code in Spring MVC Controllers

spring-interview-questions-answers

After spending some time doing sustained engineering (a.k.a. maintaining legacy code), I ventured to reduce repetitive code in Spring MVC @Controllers. I started with an abstract base controller class. But I soon found out that it was a dead-end because @RequestMapping is not inherited from (or combined with) parent classes and/or interfaces (see Spring MVC @RequestMapping Inheritance). With some free ...

Read More »

Quick tip: Referencing other Properties in Spring

spring-interview-questions-answers

In Spring property (or yaml) files we can reference other properties using the ${..} syntax. For example: 1 2 3 external.host=https://api.external.com external.productService=${external.host}/product-service external.orderService=${external.host}/order-service If we now access the external.productService property (e.g. by using the @Value annotation) we will get the value https://api.external.com/product-service. For example: 1 2 @Value("${external.productService}") private String productServiceUrl; // https://api.external.com/product-service This way we can avoid duplication of commonly used values in property ...

Read More »

What is Bean scope in Spring MVC framework with Example

spring-interview-questions-answers

Bean scope in Spring framework or Spring MVC is scope for a bean managed by Spring IOC container. You may know that Spring is a framework that is based on Dependency Injection and Inversion of Control and provides bean management facilities to Java application. In Spring-managed environment bean (Java Classes) are created and wired by the Spring framework. Spring allows ...

Read More »

Integrating JSON Schema validation in Spring using a custom HandlerMethodArgumentResolver

In previous posts we learned about JSON Schema and how we can validate a JSON document against a JSON Schema in Java. In this post we will integrate JSON Schema validation into Spring controllers using a custom HandlerMethodArgumentResolver. We will use the same JSON document and JSON Schema as in previous posts. So, what is a HandlerMethodArgumentResolver? Handler methods in ...

Read More »