Posts

Showing posts with the label Spring Boot

How to resolve 'org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ...' - using stereotype Annotations and using @Configuration, @Bean Annotation

Image
"At the end of the day, it doesn't really matter whether you use XML, annotation or Java configuration. It's important that beans are known to application context." -  Tomasz Nurkiewicz Hello everyone, in this article, we will learn how to resolve org.springframework.beans.factory. NoSuchBeanDefinitionException : No qualifying bean of type 'com.knf.dev.demo.account.HelloManager' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: Using: 1. Stereotype Annotations. 2. @Configuration, @Bean Annotation. Before going to the example just a quick overview of NoSuchBeanDefinitionException ,  @Configuration annotation, @Bean annotation, and  @Component annotation( Stereotype annotation ). NoSuchBeanDefinitionException: The 'org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.knf.dev.demo.account.HelloManager' available: expected at least 1 bean which qualifies as

How To Resolve 'org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean ....' Using @Qualifier Annotation?

Image
Hello everyone, in this article we will learn how to resolve org.springframework.beans.factory. NoUniqueBeanDefinitionException : No qualifying bean of type 'com.example.demo.components.Human' available: expected single matching bean but found 2: employee,employer using @Qualifier Annotation or using @Primary Annotation. Before going to the example just a quick overview of NoUniqueBeanDefinitionException and @Qualifier Annotation. NoUniqueBeanDefinitionException: The ' org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type available: expected single matching bean but found ' will be thrown when the bean is auto-wired that matches two or more loaded beans in the spring boot application context. As a result, the bean could not be auto-wired.  The ApplicationContext represents the Spring IoC container and is responsible for instantiating, configuring, and assembling the aforementioned beans. @Qualifier  Annotation: The @Qualifier a

Spring boot application.json properties example

Image
In this article, we will show you how to use JSON instead of the properties file or the yml file in Spring Boot by custom configuration. Before moving to the example first you must be familiar with the following components. 1.spring.factories file The file is located in src/java/resources/META-INF/spring.factories . The spring.factories file is a file that spring automatically loads when booting up. It contains references to many configuration classes. For example, org.springframework.boot.env. PropertySourceLoader =com.example.demo. JsonPropertySourceLoader Here we registered our custom Json property source loader 2. YamlPropertySourceLoader Load the resource into one or more property sources. Implementations may either return a list containing a single source or in the case of a multi-document format such as YAML a source for each document in the resource. Refer import org.springframework.boot.env. YamlPropertySourceLoader ; public class JsonPropertySourceLoader ex

Using Spring Interceptor or Using Servlet Filter How To Get a Request URL Template That Has Been Hit?

Image
In this tutorial, we will learn how to find a request URL template that has been hit using Servlet Filter or Using Spring Interceptor.  Before going to the example program just check the basis of the Servlet filter and Spring Interceptor. The Servlet Filter is used to intercept the client request and do some pre-processing before they reach the DispatcherServlet. It can also intercept the response and do post-processing before sending to the client in web application. On the other hand, The Spring Interceptor is only applied to requests that are sent to a Controller. Get request URL template using Spring Interceptor(Good approach) Demo Controller @ RequestMapping (path = "/user" ) @ RestController public class UserController { @ GetMapping (path = "/{id}" ) public ResponseEntity < Long > getAllVariables(@ PathVariable ( "id" ) Long id) { return new ResponseEntity < Long >(id, HttpStatus.OK); } } Custom