Posts

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

Learn Java 8 Stream Intermediate And Terminal Operations with Example

Image
Java is Object Oriented Programming language, being object-oriented is not bad, but it brings a lot of verbosity to the program. Java 8 introduced new libraries and programming styles, for example, functional interfaces, lambda expressions, and streams. These bring functional-style programming to the object-oriented programming capabilities of Java. Java Functional Interface and Lambda Expression help us write smaller and cleaner code by removing much boilerplate code.  Java Stream Intermediate operations and Terminal operations The intermediate operation will transform a stream into another stream, such as a map(MapperFn) or a filter(Predicate). The Terminal operation will produce a result or side-effect, such as count() or forEach(Consumer). All intermediate operations will NOT be executed without a terminal operation at the end. So the pattern will be: stream() .intemediateOperation1() .intemediateOperation2() ....................... .intemediateOperationN() .ter

Learn Java Predicate, Consumer, Function, and Supplier (Functional Interfaces) with Example

Java is Object Oriented Programming language, being object-oriented is not bad, but it brings a lot of verbosity to the program.Java 8 introduced new libraries and programming styles, for example, functional interfaces, lambda expressions, and streams. These bring functional-style programming to the object-oriented programming capabilities of Java. Java Functional Interface and Lambda Expression help us write smaller and cleaner code by removing much boilerplate code.  A functional interface contains only a single abstract method and  can include default and static methods that do have an implementation and a single unimplemented method. Here we will discuss Predicate, Consumer, Function, and Supplier. 1. Predicate Interface The Predicate is a functional interface defined in java. util. Function package , which accepts an argument and returns a boolean. This is mainly used to filter data from a Java Stream. The filter method of a stream accepts a predicate to filter the data and retur