{"id":91875,"date":"2019-05-17T13:00:21","date_gmt":"2019-05-17T10:00:21","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=91875"},"modified":"2019-05-15T20:05:57","modified_gmt":"2019-05-15T17:05:57","slug":"spring-core-annotations","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2019\/05\/spring-core-annotations.html","title":{"rendered":"Spring Core Annotations"},"content":{"rendered":"<h3 class=\"wp-block-heading\">Introduction:<\/h3>\n<p><strong>Spring annotations present in the <em>org.springframework.beans.factory.annotation<\/em> and&nbsp;<em>org.springframework.context.annotation <\/em>packages are commonly known as Spring Core annotations. <\/strong>We can divide them into two broad categories: DI-Related Annotations &amp; Context Configuration Annotations<strong>:<\/strong><\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><img decoding=\"async\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/SpringCoreAnnotations.png\" alt=\"spring annotations\" class=\"wp-image-91897\" width=\"635\" height=\"212\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/SpringCoreAnnotations.png 846w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/SpringCoreAnnotations-300x100.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/SpringCoreAnnotations-768x257.png 768w\" sizes=\"(max-width: 635px) 100vw, 635px\" \/><\/figure>\n<\/div>\n<p>In this tutorial, we\u2019ll explore all of these Spring Core annotations.<\/p>\n<h3 class=\"wp-block-heading\">DI-Related Annotations:<\/h3>\n<h3 class=\"wp-block-heading\">1. <em>@Autowired:<\/em><\/h3>\n<p><strong>We use<em> @Autowired<\/em> to mark the dependency which will be injected by the Spring container.<\/strong> It can be used with a constructor, setter or field-based injection.<\/p>\n<p><strong>Constructor Injection:<\/strong><\/p>\n<pre class=\"brush:java\">\npublic class Employee {\n    private Department dept;\n    \n    @Autowired\n    public Employee(Department dept) {\n        this.dept = dept;\n    }\n}\n<\/pre>\n<p>For a constructor-based injection, all the constructor arguments are mandatory. Also<em> Spring version 4.3<\/em> onwards, we can skip explicitly annotating the constructor with <em>@Autowired<\/em> annotation unless we have two or more of them.<\/p>\n<p><strong>Field Injection:<\/strong><\/p>\n<pre class=\"brush:java\">\npublic class Employee {\n    @Autowired\n    private Department dept;\n}\n<\/pre>\n<p><strong>Setter Injection:<\/strong><\/p>\n<pre class=\"brush:java\">\npublic class Employee {\n    private Department dept;\n \n    @Autowired\n    public void setDept(Department dept) {\n        this.dept = dept;\n    }\n}\n<\/pre>\n<p>The <em>@Autowired<\/em> annotation also takes in an optional <em>boolean<\/em> argument named <em>required<\/em>. By default, its value is set to <em>true. <\/em>We can explicitly set it to <em>false<\/em> for which Spring won\u2019t throw an exception when the auto-wiring fails.<\/p>\n<h3 class=\"wp-block-heading\">2. <em>@Qualifier:<\/em><\/h3>\n<p>We use <em>@Qualifier<\/em> along with the <em>@Autowired<\/em> annotation<strong> to avoid ambiguity when we have multiple beans of the same type.<\/strong><\/p>\n<p>Let\u2019s say we have two classes:<\/p>\n<pre class=\"brush:java\">\n@Component\npublic class Employee implements Person {}\n \n@Component\npublic class Student implements Person {}\n<\/pre>\n<p>Since both of them implements <em>Person<\/em> interface, Spring has no means to know which <em>Person <\/em>bean to inject when using <em>@Autowired<\/em>. To resolve this issue, we can use <em>@Qualifier<\/em> annotation:<\/p>\n<pre class=\"brush:java\">\npublic class Main {\n    \n    @Autowired\n    @Qualifier(\"employee\")\n    private Person person;\n}\n<\/pre>\n<p>Just like <em>@Autowired<\/em>, we can use it with a setter, constructor or field-based injection.<\/p>\n<h3 class=\"wp-block-heading\">3.<em> @Primary:<\/em><\/h3>\n<p>We now know that we can use <em>@Qualifier<\/em> along with <em>@Autowired<\/em> when we have multiple beans of the same type. However, most of the time we\u2019ll specifically need one of those bean\u2019s instance and rarely the others. <strong>We can mark the<\/strong><strong> most frequently used bean with <em>@Primary<\/em> annotation. With it, all unqualified injections will resolve to our primary bean.<\/strong><\/p>\n<pre class=\"brush:java\">\n@Primary\n@Component\npublic class Employee implements Person {}\n \n@Component\npublic class Student implements Person {}\n \n@Component\npublic class EmployeeHandler {\n \n    @Autowired\n    private Person employee;  \n}\n \n@Component\npublic class StudentHandler {\n \n    @Autowired\n    @Qualifier(\"student\")\n    private Person student;    \n}\n<\/pre>\n<p>Since we have given a qualifier in <em>StudentHandler<\/em>, the <em>Student<\/em> bean will be injected. For our <em>EmployeeHandler<\/em>, we have skipped the qualifier and so an <em>Employee<\/em> will be injected. This is so as <em>Employee<\/em> is our primary bean of type <em>Person<\/em>.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h3 class=\"wp-block-heading\">4. <em>@Bean:<\/em><\/h3>\n<p><strong><em>@Bean<\/em> is a method-level annotation used in <em>@Configuration<\/em> class.<\/strong> It marks a factory method used to instantiate a Spring bean:<\/p>\n<pre class=\"brush:java\">\n@Configuration\npublic class AppConfig {\n    ...\n    @Bean\n    public Employee employee() {\n        return new Employee();\n    }\n}\n<\/pre>\n<p>When a new instance of the return type is required, Spring will call these methods. The instantiated bean has the same name as that of the factory method. If we want to give it a different name, we can do so using the name argument of this annotation.<\/p>\n<pre class=\"brush:java\">\n@Bean(\"myEmp\")\npublic Employee employee() {\n    return new Employee();\n}\n<\/pre>\n<h3 class=\"wp-block-heading\">5. <em>@Lazy:<\/em><\/h3>\n<p>Spring, by default, instantiates all singleton beans at the time of application startup. If we want to prevent this eager initialization, we can use<em> @Lazy<\/em> annotation. When we use <em>@Lazy<\/em> annotation, the bean will be first instantiated on a user request.<\/p>\n<p>We can place this annotation on:<\/p>\n<ul class=\"wp-block-list\">\n<li><em>@Bean<\/em> annotated method to delay a specific bean instantiation<\/li>\n<li><em>a class annotated with @Configuration<\/em> to delay creating all beans defined in this class<\/li>\n<li>a class marked as<em> @Component<\/em>, which will then lazy load<\/li>\n<li>along with <em>@Autowired<\/em> annotation over a constructor, field or a setter. Here as well, container will not load the injected dependency until we receive the first user request<\/li>\n<\/ul>\n<pre class=\"brush:java\">\n@Configuration\npublic class AppConfig {\n \n    @Bean\n    @Lazy\n    public Employee employee() {\n        return new Employee();\n    }\n \n    @Bean\n    public Student student() {\n        return new Student();\n    }\n}\n<\/pre>\n<p>It also accepts an optional <em>boolean<\/em> argument <em>value <\/em>with a default set to <em>true<\/em>. If we set it to <em>false<\/em>, it will eagerly instantiate the bean. This can come handy when we have a <em>Configuration<\/em> to load all beans lazily except a few.<\/p>\n<h3 class=\"wp-block-heading\">6. <em>@Required:<\/em><\/h3>\n<p><strong><em>@Required<\/em> is a method-level annotation used on setter methods of a bean. It simply marks the dependencies we want to populate using an XML:<\/strong><\/p>\n<pre class=\"brush:java\">\n@Required\nvoid setName(String name) {\n    this.name = name;\n}\n<\/pre>\n<pre class=\"brush:xml\">\n&lt;bean class=\"com.programmergirl.spring.Employee\"&gt;\n    &lt;property name=\"name\" value=\"Joey\" \/&gt;\n&lt;\/bean&gt;\n<\/pre>\n<p>On failing to do so, it will throw a <em>BeanInitializationException<\/em>.<\/p>\n<h3 class=\"wp-block-heading\">7.<em> @Value:<\/em><\/h3>\n<p><strong>We can use <em>@Value<\/em> to inject property values defined in external sources into our beans.<\/strong> For instance, we can define a few properties in our<em> application.yaml<\/em> or <em>application.properties<\/em> file:<\/p>\n<pre class=\"brush:java\">\njames.employee.id = 2563\n<\/pre>\n<p>And then inject that value into our bean:<\/p>\n<pre class=\"brush:java\">\n@Value(\"${james.employee.id}\")\nprivate String jamesEmpId;\n<\/pre>\n<p>We can also use <em>@Value<\/em> with SpEL.<\/p>\n<h3 class=\"wp-block-heading\">8.<em> @DependsOn:<\/em><\/h3>\n<p>The <em>@DependsOn<\/em> annotation can force the Spring container to initialize one or more beans before the bean annotated with<em> @DependsOn<\/em> annotation.<\/p>\n<p><strong>Usually, this behavior is automatic. We\u2019ll only need it when we have implicit dependencies, for example, loading a JDBC driver.<\/strong><\/p>\n<p>We can use <em>@DependsOn<\/em> annotation on any class directly or indirectly annotated with <em>@Component<\/em> or on factory methods annotated with<em> @Bean<\/em>.<\/p>\n<pre class=\"brush:java\">\n@Configuration\npublic class AppConfig {\n \n    @Bean\n    @DependsOn(value = {\"employee\"})\n    public Dependent dependent() {\n        return new Dependent();\n    }\n \n}\n<\/pre>\n<h3 class=\"wp-block-heading\">9. <em>@Scope<\/em>:<\/h3>\n<p><strong>We use <em>@Scope<\/em> annotation to define the scope of a <em>@Component<\/em> class or a <em>@Bean<\/em> definition.<\/strong> It can be either<em> singleton, prototype, request, session, globalSession<\/em> or some custom scope.<\/p>\n<pre class=\"brush:java\">\n@Component\n@Scope(\"prototype\")\npublic class Employee {}\n<\/pre>\n<h3 class=\"wp-block-heading\">10. <em>@Lookup:<\/em><\/h3>\n<p>A method annotated with <em>@Lookup<\/em> tells Spring to return an instance of the method\u2019s return type when we invoke it. It\u2019s useful for:<\/p>\n<ul class=\"wp-block-list\">\n<li>injecting a prototype bean into a singleton instance<\/li>\n<li>procedurally injecting dependencies<\/li>\n<\/ul>\n<p>To learn how to inject a prototype bean into a singleton bean, please feel free to refer<a href=\"http:\/\/www.programmergirl.com\/spring-injecting-prototype-beans-into-singleton-instance\/\"> to this article.<\/a><\/p>\n<h3 class=\"wp-block-heading\">Context Configuration Annotations:<\/h3>\n<p>We can configure our application context using the below annotations:<\/p>\n<h3 class=\"wp-block-heading\">1. <em>@Profile:<\/em><\/h3>\n<p><strong>If we want Spring to use a <em>@Component<\/em> class or a <em>@Bean<\/em> method only when a specific profile is active, we can mark it with <em>@Profile<\/em> annotation.<\/strong> We can mention the name of the profile with the <em>value<\/em> argument of this annotation:<\/p>\n<pre class=\"brush:java\">\n@Component\n@Profile(\"dev\")\npublic class Employee {}\n<\/pre>\n<h3 class=\"wp-block-heading\">2. <em>@Import:<\/em><\/h3>\n<p>Using this annotation, we can specify one or more <em>@Configuration<\/em> classes to import.<\/p>\n<pre class=\"brush:java\">\n@Configuration\npublic class EmployeeConfig {\n \n    @Bean\n    public Employee employee() {\n        return new Employee();\n    }\n}\n \n@Configuration\n@Import(EmployeeConfig.class)\npublic class AppConfig {\n \n    @Bean\n    public Student student() {\n        return new Student();\n    }\n}\n<\/pre>\n<p>With this, we can just specify the <em>AppConfig<\/em> class explicitly while initializing an application context. It will automatically import beans defined in our <em>EmployeeConfig.<\/em><\/p>\n<h3 class=\"wp-block-heading\">3.<em> @ImportResource:<\/em><\/h3>\n<p>We can use this annotation <strong>to load beans into the <em>ApplicationContext<\/em> from the <em>applicationContext.xml<\/em> file<\/strong>:<\/p>\n<pre class=\"brush:java\">\n@Configuration\n@ImportResource({\"classpath*:applicationContext.xml\"})\npublic class AppConfig {\n}\n<\/pre>\n<h3 class=\"wp-block-heading\">4. <em>@PropertySource:<\/em><\/h3>\n<p>This annotation provides a convenient way to define a property file to use for application settings:<\/p>\n<pre class=\"brush:java\">\n@Configuration\n@PropertySource(\"classpath:appConfig.properties\")\npublic class DatabaseConfig implements InitializingBean {\n \n    @Autowired\n    Environment env;\n    \n    ...\n \n    void setDbConfig() {\n        DataSourceConfig config = new DataSourceConfig();\n        config.setDriver(env.getProperty(\"jdbc.driver\"));\n        config.setUrl(env.getProperty(\"jdbc.url\"));\n        config.setUsername(env.getProperty(\"jdbc.username\"));\n        config.setPassword(env.getProperty(\"jdbc.password\"));\n    }\n \n}\n<\/pre>\n<h3 class=\"wp-block-heading\">5. <em>@PropertySources:<\/em><\/h3>\n<p>We can use this annotation to specify multiple <em>@PropertySource <\/em>configurations:<\/p>\n<pre class=\"brush:java\">\n@Configuration\n@PropertySources({ \n    @PropertySource(\"classpath:\/student.properties\"),\n    @PropertySource(\"classpath:\/employee.properties\"),\n    @PropertySource(\"classpath:\/database.properties\")\n})\nclass AppConfig {}\n<\/pre>\n<p><strong>Java 8 onwards, we can achieve the same with just using repeated annotation feature i.e. directly specifying multiple <em>@PropertySource<\/em> annotations.<\/strong><\/p>\n<h3 class=\"wp-block-heading\">Conclusion:<\/h3>\n<p>In this article, we covered the most common Spring core annotations. We can use them either for bean wiring or configuring an application context.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>\n<p>Published on Java Code Geeks with permission by Shubhra Srivastava, partner at our <a href=\"\/\/www.javacodegeeks.com\/join-us\/jcg\/\" target=\"_blank\" rel=\"noopener noreferrer\">JCG program<\/a>. See the original article here: <a href=\"http:\/\/www.programmergirl.com\/spring-core-annotations\/\" target=\"_blank\" rel=\"noopener noreferrer\">Spring Core Annotations<\/a><\/p>\n<p>Opinions expressed by Java Code Geeks contributors are their own.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: Spring annotations present in the org.springframework.beans.factory.annotation and&nbsp;org.springframework.context.annotation packages are commonly known as Spring Core annotations. We can divide them into two broad categories: DI-Related Annotations &amp; Context Configuration Annotations: In this tutorial, we\u2019ll explore all of these Spring Core annotations. DI-Related Annotations: 1. @Autowired: We use @Autowired to mark the dependency which will be &hellip;<\/p>\n","protected":false},"author":82253,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[30],"class_list":["post-91875","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-spring"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Spring Core Annotations - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn about spring annotations? Check our article exploring the two Spring Core annotations DI-Related Annotations &amp; Context Configuration.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2019\/05\/spring-core-annotations.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Core Annotations - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn about spring annotations? Check our article exploring the two Spring Core annotations DI-Related Annotations &amp; Context Configuration.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2019\/05\/spring-core-annotations.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2019-05-17T10:00:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Shubhra Srivastava\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shubhra Srivastava\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/05\\\/spring-core-annotations.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/05\\\/spring-core-annotations.html\"},\"author\":{\"name\":\"Shubhra Srivastava\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/b73b076dc62e72de203df7018d398e56\"},\"headline\":\"Spring Core Annotations\",\"datePublished\":\"2019-05-17T10:00:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/05\\\/spring-core-annotations.html\"},\"wordCount\":1006,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/05\\\/spring-core-annotations.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"Spring\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/05\\\/spring-core-annotations.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/05\\\/spring-core-annotations.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/05\\\/spring-core-annotations.html\",\"name\":\"Spring Core Annotations - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/05\\\/spring-core-annotations.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/05\\\/spring-core-annotations.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2019-05-17T10:00:21+00:00\",\"description\":\"Interested to learn about spring annotations? Check our article exploring the two Spring Core annotations DI-Related Annotations & Context Configuration.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/05\\\/spring-core-annotations.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/05\\\/spring-core-annotations.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/05\\\/spring-core-annotations.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/05\\\/spring-core-annotations.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Spring Core Annotations\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/b73b076dc62e72de203df7018d398e56\",\"name\":\"Shubhra Srivastava\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9e5d3b016140986463a886392b8400e55ed0aa7742ef29b86a54bd8d5743b68a?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9e5d3b016140986463a886392b8400e55ed0aa7742ef29b86a54bd8d5743b68a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9e5d3b016140986463a886392b8400e55ed0aa7742ef29b86a54bd8d5743b68a?s=96&d=mm&r=g\",\"caption\":\"Shubhra Srivastava\"},\"description\":\"Shubhra is a software professional and founder of ProgrammerGirl. She has a great experience with Java\\\/J2EE technologies and frameworks. She loves the amalgam of programming and coffee :)\",\"sameAs\":[\"http:\\\/\\\/www.programmergirl.com\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/shubhra-srivastava224\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/shubhra-srivastava\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring Core Annotations - Java Code Geeks","description":"Interested to learn about spring annotations? Check our article exploring the two Spring Core annotations DI-Related Annotations & Context Configuration.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2019\/05\/spring-core-annotations.html","og_locale":"en_US","og_type":"article","og_title":"Spring Core Annotations - Java Code Geeks","og_description":"Interested to learn about spring annotations? Check our article exploring the two Spring Core annotations DI-Related Annotations & Context Configuration.","og_url":"https:\/\/www.javacodegeeks.com\/2019\/05\/spring-core-annotations.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2019-05-17T10:00:21+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Shubhra Srivastava","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Shubhra Srivastava","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2019\/05\/spring-core-annotations.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/05\/spring-core-annotations.html"},"author":{"name":"Shubhra Srivastava","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/b73b076dc62e72de203df7018d398e56"},"headline":"Spring Core Annotations","datePublished":"2019-05-17T10:00:21+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/05\/spring-core-annotations.html"},"wordCount":1006,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/05\/spring-core-annotations.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["Spring"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2019\/05\/spring-core-annotations.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2019\/05\/spring-core-annotations.html","url":"https:\/\/www.javacodegeeks.com\/2019\/05\/spring-core-annotations.html","name":"Spring Core Annotations - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/05\/spring-core-annotations.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/05\/spring-core-annotations.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2019-05-17T10:00:21+00:00","description":"Interested to learn about spring annotations? Check our article exploring the two Spring Core annotations DI-Related Annotations & Context Configuration.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/05\/spring-core-annotations.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2019\/05\/spring-core-annotations.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2019\/05\/spring-core-annotations.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2019\/05\/spring-core-annotations.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Spring Core Annotations"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/b73b076dc62e72de203df7018d398e56","name":"Shubhra Srivastava","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9e5d3b016140986463a886392b8400e55ed0aa7742ef29b86a54bd8d5743b68a?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9e5d3b016140986463a886392b8400e55ed0aa7742ef29b86a54bd8d5743b68a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9e5d3b016140986463a886392b8400e55ed0aa7742ef29b86a54bd8d5743b68a?s=96&d=mm&r=g","caption":"Shubhra Srivastava"},"description":"Shubhra is a software professional and founder of ProgrammerGirl. She has a great experience with Java\/J2EE technologies and frameworks. She loves the amalgam of programming and coffee :)","sameAs":["http:\/\/www.programmergirl.com","https:\/\/www.linkedin.com\/in\/shubhra-srivastava224\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/shubhra-srivastava"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/91875","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/82253"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=91875"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/91875\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=91875"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=91875"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=91875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}