![]() ![]() This is a component class that is marked using the annotation and implements the Award interface. Each class that implements this interface will have to override the award () method. In this section, we will discuss different types of annotations with their examples. This is an interface Award that contains a award() abstract method. The annotation indicates that this is not a simple class but a configuration class and the annotation is used to indicate the component location in our spring project. This is a configuration file in Java which is an alternate of the applicationContext.xml file that we created for the XML-based configuration example. Writer writer = context.getBean("fictionWriter", Writer.class) Import .AnnotationConfigApplicationContext ĪnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class) The AnnotationConfigApplicationContext class is used to create an object for application context. This file contains the code to create an IOC container for our application. The project is a Maven-Based Spring Project and contains the following files. In this topic, we are using the annotation to specify the dependency instance. If we don't use this annotation in the given project then we get an error like:Ĭaused by: .NoUniqueBeanDefinitionException: No qualifying bean of type '' available: expected single matching bean but found 3: bookerAward,nationalAward,pulitzerAward If we have more than one bean of the same type and want to wire only one of them then use the annotation along with to specify which exact bean will be wired. ![]() ![]() The annotation in Spring is used to differentiate a bean among the same type of bean objects. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |