Here include required Spring libraries using
Add External JARs option. Add
CGLIB.jar from your Java installation directory and
ASM.jar library which can be downloaded from below link.
Jar files
HelloWorldConfig.java file
[java]package splessons;
import org.springframework.context.annotation.*;
@Configuration
public class HelloWorldConfig {
@Bean
public HelloWorld helloWorld(){
return new HelloWorld();
}
}[/java]
Annotating a class with the
@Configuration demonstrates that the class can be utilized by the Spring IoC compartment as a wellspring of bean definitions. The @Bean explanation tells Spring that a technique annotated on with @Bean will give back an object that ought to be enrolled as a bean in the Spring application setting.
HelloWorld.java file
[java]package splessons;
public class HelloWorld {
private String message;
public void setMessage(String message){
this.message = message;
}
public void getMessage(){
System.out.println("Your Message : " + message);
}
}[/java]
Here performed SET nad GET methods.
MainApp.java file
[java]package splessons;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;
public class MainApp {
public static void main(String[] args) {
ApplicationContext ctx =
new AnnotationConfigApplicationContext(HelloWorldConfig.class);
HelloWorld helloWorld = ctx.getBean(HelloWorld.class);
helloWorld.setMessage("Hello World!");
helloWorld.getMessage();
}
}[/java]
The Application Context is spring's more best in class holder. Like BeanFactory it can stack bean definitions, wire beans together and administer beans upon solicitation. Also it includes more enterprise-specific usefulness, for example, the capacity to determine literary messages from a properties document and the capacity to distribute application events to interested event listeners. This container is characterized by the org.springframework.context.ApplicationContext interface.
Output
[java]Your Message : Hello World![/java]