Ignite Spring bean allows to bypass
Ignition methods.
In other words, this bean class allows to inject new grid instance from
Spring configuration file directly without invoking static
Ignition methods. This class can be wired directly from
Spring and can be referenced from within other Spring beans.
By virtue of implementing
DisposableBean and
SmartInitializingSingletoninterfaces,
IgniteSpringBean automatically starts and stops underlying
grid instance.
A note should be taken that Ignite instance is started after all other
Spring beans have been initialized and right before Spring context is refreshed.
That implies that it's not valid to reference IgniteSpringBean from
any kind of Spring bean init methods like
javax.annotation.PostConstruct.
If it's required to reference IgniteSpringBean for other bean
initialization purposes, it should be done from a
ContextRefreshedEventlistener method declared in that bean.
Spring Configuration Example
Here is a typical example of describing it in Spring file:
<bean id="mySpringBean" class="org.apache.ignite.IgniteSpringBean">
<property name="configuration">
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="igniteInstanceName" value="mySpringGrid"/>
</bean>
</property>
</bean>
Or use default configuration:
<bean id="mySpringBean" class="org.apache.ignite.IgniteSpringBean"/>
Java Example
Here is how you may access this bean from code:
AbstractApplicationContext ctx = new FileSystemXmlApplicationContext("/path/to/spring/file");
// Register Spring hook to destroy bean automatically.
ctx.registerShutdownHook();
Ignite ignite = (Ignite)ctx.getBean("mySpringBean");