package com.learningSpring.learningSpring;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class HelloWorldConfiguration {
// Spring Framework
@Bean
public String name(){
// this method will create a bean in the Spring Container
return "Iqra";
}
@Bean
public int age(){
// this method will create a bean in the Spring Container
return 11;
}
}
Spring Context
package com.learningSpring.learningSpring;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class HelloWorldJava02 {
public static void main(String[] args) {
//Lunch a Spring context
var context=new AnnotationConfigApplicationContext(HelloWorldJava02.class);
//Configure the things that we want to manage Spring Framework @Configuration
// How to get Bean from the Spring Context is
System.out.println(context.getBean("name"));// name is the method name
System.out.println(context.getBean("age"));
}
}