Bootstraping Spring core using the context

AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.scan("tech.lacambra.prototype.statesmachine");
context.refresh();

At this point al found beans has been registered and can be used. As an example code would go further as follows, taking care that ExStateMachine.class  is annotated as @Component :

ExStateMachine machine = context.getBeanFactory().getBean(ExStateMachine.class);
machine.doSignals();

System.out.println("done!");

There are several available conext, all implementing the interface:

org.springframework.context.ApplicationContext
org.springframework.context:
ConfigurableApplicationContext.java

package org.springframework.context.annotation:
 AnnotationConfigApplicationContext.java

package org.springframework.context.support:
 AbstractApplicationContext.java
 AbstractRefreshableApplicationContext.java
 AbstractRefreshableConfigApplicationContext.java
 AbstractXmlApplicationContext.java
 ClassPathXmlApplicationContext.java
 FileSystemXmlApplicationContext.java
 GenericApplicationContext.java
 GenericGroovyApplicationContext.java
 GenericXmlApplicationContext.java
 StaticApplicationContext.java

package org.springframework.jca.context:
 ResourceAdapterApplicationContext.java

Leave a Reply