Spring @Configuration Annotation Example

0

In this article, we will see how to build a spring container using @Configuration annotation. We will see some examples of building spring container using spring @Configuration.

Configuration Annotation

When a class is annotated with @Configuration it indicates that it contains source of bean definitions, methods annotated with @Bean. When the spring framework comes across a @Configuration class, not only the @Configuration class itself is registered as a bean definition, even all the declared @Bean methods within the class are also registered as bean definitions.
The @Configuration class itself is itself annotated with @Component. The main difference between two is @Configuration classes allows inter-bean dependencies where one @Bean method can invoke another @Bean method.

Configuration:

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Configuration {
...
}

When @Bean methods are declared within classes that are not annotated with @Configuration they are referred to as being processed in a ‘lite’ mode.
Let’s declare two beans A and B.

A:

package com.javarticles.spring.annotations;

public class A {
}

B:

package com.javarticles.spring.annotations;

public class B {
}

We will annotate SpringConfigurationAnnotationExample with @Configuration, it contain @Bean methods a() and b(). We can provide the bean name as value of the annotation.

SpringConfigurationAnnotationExample:

package com.javarticles.spring.annotations;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration("mainBean")
public class SpringConfigurationAnnotationExample {
    @Bean
    public A a() {
        return new A();
    }

    @Bean
    public B b() {
        return new B();
    }
}

Bootstrapping @Configuration classes via AnnotationConfigApplicationContext

If the spring beans are defined in XML we will use ClassPathXmlApplicationContext to build the spring container. If we want spring to build the container using @Configuration annotation then we will use AnnotationConfigApplicationContext. In our example, SpringConfigurationAnnotationExample is the class that contains other bean definitions. There may be more classes annotated with @Configuration. We will pass in all those class to register() method and refresh the container.

AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(SpringConfigurationAnnotationExample.class);
ctx.refresh();

SpringConfigurationAnnotationExample:

package com.javarticles.spring.annotations;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration("mainBean")
public class SpringConfigurationAnnotationExample {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
        try {
            ctx.register(SpringConfigurationAnnotationExample.class);
            ctx.refresh();
            SpringConfigurationAnnotationExample mainBean = (SpringConfigurationAnnotationExample) ctx
                    .getBean("mainBean");
            System.out.println(mainBean.a());
            System.out.println(mainBean.b());
        } finally {
            ctx.close();
        }
    }

    @Bean
    public A a() {
        return new A();
    }

    @Bean
    public B b() {
        return new B();
    }
}

Output:

Jan 13, 2016 12:50:31 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.spring[email protected]6e2c634b: startup date [Wed Jan 13 12:50:31 IST 2016]; root of context hierarchy
Jan 13, 2016 12:50:31 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.s[email protected]357246de: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,mainBean,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,a,b]; root of factory hierarchy
[email protected]
[email protected]
Jan 13, 2016 12:50:31 PM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing org.spring[email protected]6e2c634b: startup date [Wed Jan 13 12:50:31 IST 2016]; root of context hierarchy
Jan 13, 2016 12:50:31 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.s[email protected]357246de: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,mainBean,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,a,b]; root of factory hierarchy

Import Annotation

Suppose we want to import other @Configuration classes, we can do that using @Import annotation and passing in those classes as annotation value.
We can access the registered beans using @Autowired injection. Either the bean itself can be autowired, or the configuration class which itself is a registered bean instance can be autowired.

In our example, class C is another @Configuration class which we will import it using @Import(C.class).

C:

package com.javarticles.spring.package1;

import org.springframework.context.annotation.Configuration;

@Configuration
public class C {

}

SpringConfigurationAnnotationExample:

package com.javarticles.spring.annotations;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import com.javarticles.spring.package1.C;

@Configuration("mainBean")
@Import(C.class)
public class SpringConfigurationAnnotationExample {
    @Autowired
    private C c;    

    public static void main(String[] args) {
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
        try {
            ctx.register(SpringConfigurationAnnotationExample.class);
            ctx.refresh();
            SpringConfigurationAnnotationExample mainBean = (SpringConfigurationAnnotationExample) ctx
                    .getBean("mainBean");
            System.out.println(mainBean.a());
            System.out.println(mainBean.b());
            System.out.println(mainBean.c());
        } finally {
            ctx.close();
        }
    }

    @Bean
    public A a() {
        return new A();
    }

    @Bean
    public B b() {
        return new B();
    }
    
    public C c() {
        return c;
    }
}

Output:

Jan 13, 2016 12:53:55 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.spring[email protected]6e2c634b: startup date [Wed Jan 13 12:53:55 IST 2016]; root of context hierarchy
Jan 13, 2016 12:53:55 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.s[email protected]d7b1517: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,mainBean,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,com.javarticles.spring.package1.C,a,b]; root of factory hierarchy
[email protected]
[email protected]
[email protected]7e1bb
Jan 13, 2016 12:53:55 PM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing org.spring[email protected]6e2c634b: startup date [Wed Jan 13 12:53:55 IST 2016]; root of context hierarchy
Jan 13, 2016 12:53:55 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.s[email protected]d7b1517: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,mainBean,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,com.javarticles.spring.package1.C,a,b]; root of factory hierarchy

Component Scan

Suppose we want to scan an entire package or a set of packages, using @Import may not work, in such case we can use the @ComponentScan. If the classes reside in the same package as the bootstrap @Configuration class then we don’t have to specify the package name. Spring can automatically detect stereotyped classes and register corresponding bean definitions contained in @Configuration classes. In order to auto-detect these classes and register the corresponding beans, we need to add @ComponentScan to your @Configuration class and pass in the package names.

Since @Configuration classes are meta-annotated with @Component, they too will be included in component-scanning.

In our example, Config1 and Config2 are the configuration classes annotated with @Configuration. We want them to be registered to the spring container created in class SpringConfigurationAnnotationExample. All we have to do is add @ComponentScan annotation to SpringConfigurationAnnotationExample and then we can inject the beans using @Autowired or get the bean from the container using getBean().

Config1:

package com.javarticles.spring.annotations;

import org.springframework.context.annotation.Configuration;

@Configuration
public class Config1 {

}

Config2:

package com.javarticles.spring.annotations;

import org.springframework.context.annotation.Configuration;

@Configuration
public class Config2 {

}

SpringConfigurationAnnotationExample:

package com.javarticles.spring.annotations;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import com.javarticles.spring.package1.C;

@Configuration("mainBean")
@Import(C.class)
@ComponentScan
public class SpringConfigurationAnnotationExample {
    @Autowired
    private C c;    

    @Autowired
    private Config1 cfg1;
    
    public static void main(String[] args) {
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
        try {
            ctx.register(SpringConfigurationAnnotationExample.class);
            ctx.refresh();
            SpringConfigurationAnnotationExample mainBean = (SpringConfigurationAnnotationExample) ctx
                    .getBean("mainBean");
            System.out.println(mainBean.a());
            System.out.println(mainBean.b());
            System.out.println(mainBean.c());
            System.out.println(mainBean.cfg1());
            System.out.println(ctx.getBean("config2"));
        } finally {
            ctx.close();
        }
    }

    @Bean
    public A a() {
        return new A();
    }

    @Bean
    public B b() {
        return new B();
    }
    
    public C c() {
        return c;
    }
    
    public Config1 cfg1() {
        return cfg1;
    }
}

Output:

Jan 13, 2016 12:58:11 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.spring[email protected]6e2c634b: startup date [Wed Jan 13 12:58:11 IST 2016]; root of context hierarchy
Jan 13, 2016 12:58:11 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.s[email protected]47f37ef1: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,mainBean,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,config1,config2,com.javarticles.spring.package1.C,a,b]; root of factory hierarchy
[email protected]
[email protected]
[email protected]651f3
com.ja[email protected]38bc8ab5
com.ja[email protected]687080dc
Jan 13, 2016 12:58:11 PM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing org.spring[email protected]6e2c634b: startup date [Wed Jan 13 12:58:11 IST 2016]; root of context hierarchy
Jan 13, 2016 12:58:11 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.s[email protected]47f37ef1: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,mainBean,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,config1,config2,com.javarticles.spring.package1.C,a,b]; root of factory hierarchy

Nested Static Class with @Configuration

We can also provide nested @Configuration classes, the nested classes will be registered automatically as we register the enclosing @Configurationclass.
If such an annotation contains no name value, the default bean name generator returns the un-capitalized non-qualified class name. In the below example, enclosing class is SpringConfigurationAnnotationExample and nested class is NestedConfig, the bean name of nested class would be “springConfigurationAnnotationExample.NestedConfig”.

SpringConfigurationAnnotationExample:

package com.javarticles.spring.annotations;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import com.javarticles.spring.package1.C;

@Configuration("mainBean")
@Import(C.class)
@ComponentScan
public class SpringConfigurationAnnotationExample {
    @Autowired
    private C c;    

    @Autowired
    private Config1 cfg1;
    
    public static void main(String[] args) {
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
        try {
            ctx.register(SpringConfigurationAnnotationExample.class);
            ctx.refresh();
            SpringConfigurationAnnotationExample mainBean = (SpringConfigurationAnnotationExample) ctx
                    .getBean("mainBean");
            System.out.println(mainBean.a());
            System.out.println(mainBean.b());
            System.out.println(mainBean.c());
            System.out.println(mainBean.cfg1());
            System.out.println(ctx.getBean("config2"));
            System.out
            .println(ctx
                    .getBean("springConfigurationAnnotationExample.NestedConfig"));
        } finally {
            ctx.close();
        }
    }

    @Bean
    public A a() {
        return new A();
    }

    @Bean
    public B b() {
        return new B();
    }
    
    public C c() {
        return c;
    }
    
    public Config1 cfg1() {
        return cfg1;
    }

    @Configuration
    static class NestedConfig {
    }
}

Output:

Jan 13, 2016 12:59:46 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.spring[email protected]6e2c634b: startup date [Wed Jan 13 12:59:46 IST 2016]; root of context hierarchy
Jan 13, 2016 12:59:46 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.s[email protected]47f37ef1: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,mainBean,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,config1,config2,springConfigurationAnnotationExample.NestedConfig,com.javarticles.spring.package1.C,a,b]; root of factory hierarchy
[email protected]
[email protected]
com.javarti[email protected]
com.ja[email protected]7a9273a8
com.ja[email protected]26a7b76d
com.javarticles.spring.annotations.SpringConfigu[email protected]4abdb505
Jan 13, 2016 12:59:47 PM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing org.spring[email protected]6e2c634b: startup date [Wed Jan 13 12:59:46 IST 2016]; root of context hierarchy
Jan 13, 2016 12:59:47 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.s[email protected]47f37ef1: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,mainBean,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,config1,config2,springConfigurationAnnotationExample.NestedConfig,com.javarticles.spring.package1.C,a,b]; root of factory hierarchy

Bootstrap @Configuration classes using annotation-config element

We can also use <context:annotation-config/> to enable ConfigurationClassPostProcessor and other annotation-related post processors that facilitate registering @Configuration classes. We will have to then include the main @Configuration class as a bean to trigger the bean registration process.

annotationConfigContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	x>i:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
		
		<context:annotation-config/>
		
		<bean name="mainBean" class="com.javarticles.spring.annotations.SpringConfigurationAnnotationExample"/>

</beans>

SpringCfgBootstrapViaXML:

package com.javarticles.spring.annotations;

import org.springframework.context.support.ClassPathXmlApplicationContext;


public class SpringCfgBootstrapViaXML {

    public static void main(String[] args) {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("annotationConfigContext.xml");
        printBeans(ctx);
    }
    
    private static void printBeans(ClassPathXmlApplicationContext ctx) {
        try {
            SpringConfigurationAnnotationExample mainBean = (SpringConfigurationAnnotationExample) ctx
                    .getBean("mainBean");
            System.out.println(mainBean.a());
            System.out.println(mainBean.b());
            System.out.println(mainBean.c());
            System.out.println(mainBean.cfg1());
            System.out.println(ctx.getBean("config2"));
            System.out
            .println(ctx
                    .getBean("springConfigurationAnnotationExample.NestedConfig"));
        } finally {
            ctx.close();
        }
    }
}

Output:

Jan 13, 2016 2:57:45 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org[email protected]7eda2dbb: startup date [Wed Jan 13 14:57:45 IST 2016]; root of context hierarchy
Jan 13, 2016 2:57:45 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [annotationConfigContext.xml]
[email protected]
[email protected]
com[email protected]b59d31
com.javartic[email protected]62fdb4a6
com.javartic[email protected]11e21d0e
com.javarticles.spring.annotations.SpringConfiguration[email protected]1dd02175
Jan 13, 2016 2:57:46 PM org.springframework.context.support.ClassPathXmlApplicationContext doClose

Bootstrap @Configuration classes using component-scan element

The use of implicitly enables the functionality of . There is usually no need to include the element when using .
In the example above, the com.acme package will be scanned, looking for any @Component-annotated classes, and those classes will be registered as Spring bean definitions within the container. AnnotationConfigApplicationContext exposes the scan(String…​) method to allow for the same component-scanning functionality:

componentScanContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
		
		<context:component-scan base-package="com.javarticles.spring.annotations"/>

</beans>

SpringCfgBootstrapViaXML:

package com.javarticles.spring.annotations;

import org.springframework.context.support.ClassPathXmlApplicationContext;


public class SpringCfgBootstrapViaXML {

    public static void main(String[] args) {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("annotationConfigContext.xml");
        printBeans(ctx);
        ctx = new ClassPathXmlApplicationContext("componentScanContext.xml");
        printBeans(ctx);
    }
    
    private static void printBeans(ClassPathXmlApplicationContext ctx) {
        try {
            SpringConfigurationAnnotationExample mainBean = (SpringConfigurationAnnotationExample) ctx
                    .getBean("mainBean");
            System.out.println(mainBean.a());
            System.out.println(mainBean.b());
            System.out.println(mainBean.c());
            System.out.println(mainBean.cfg1());
            System.out.println(ctx.getBean("config2"));
            System.out
            .println(ctx
                    .getBean("springConfigurationAnnotationExample.NestedConfig"));
        } finally {
            ctx.close();
        }
    }
}

Output:

Jan 13, 2016 2:31:55 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org[email protected]433c675d: startup date [Wed Jan 13 14:31:55 IST 2016]; root of context hierarchy
Jan 13, 2016 2:31:55 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [annotationConfigContext.xml]
Jan 13, 2016 2:31:56 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.s[email protected]6fb554cc: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,com.javarticles.spring.annotations.SpringConfigurationAnnotationExample#0,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,config1,config2,springConfigurationAnnotationExample.NestedConfig,mainBean,com.javarticles.spring.package1.C,a,b]; root of factory hierarchy
[email protected]
[email protected]
[email protected]3a213
com.ja[email protected]52525845
com.ja[email protected]3b94d659
com.javarticles.spring.annotations.SpringConfig[email protected]24b1d79b
Jan 13, 2016 2:31:56 PM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing org[email protected]433c675d: startup date [Wed Jan 13 14:31:55 IST 2016]; root of context hierarchy
Jan 13, 2016 2:31:56 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.s[email protected]6fb554cc: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,com.javarticles.spring.annotations.SpringConfigurationAnnotationExample#0,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,config1,config2,springConfigurationAnnotationExample.NestedConfig,mainBean,com.javarticles.spring.package1.C,a,b]; root of factory hierarchy
Jan 13, 2016 2:31:56 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org[email protected]281e3708: startup date [Wed Jan 13 14:31:56 IST 2016]; root of context hierarchy
Jan 13, 2016 2:31:56 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [componentScanContext.xml]
Jan 13, 2016 2:31:56 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.s[email protected]48a242ce: defining beans [config1,config2,springConfigurationAnnotationExample.NestedConfig,mainBean,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,com.javarticles.spring.package1.C,a,b]; root of factory hierarchy
Jan 13, 2016 2:31:56 PM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing org[email protected]281e3708: startup date [Wed Jan 13 14:31:56 IST 2016]; root of context hierarchy
Jan 13, 2016 2:31:56 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.s[email protected]48a242ce: defining beans [config1,config2,springConfigurationAnnotationExample.NestedConfig,mainBean,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,com.javarticles.spring.package1.C,a,b]; root of factory hierarchy
[email protected]
[email protected]
[email protected]e5a13
com.ja[email protected]3439f68d
com.ja[email protected]dbd940d
com.javarticles.spring.annotations.SpringConfig[email protected]71d15f18

Download the source code

This was all about spring @configuration annotation.

You can download the source code here: springConfigurationAnnotation.zip
Share.

Comments are closed.