Class IgniteSpringBean

  • All Implemented Interfaces:
    Externalizable, Serializable, AutoCloseable, Ignite, org.springframework.beans.factory.Aware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.SmartInitializingSingleton, org.springframework.context.ApplicationContextAware

    public class IgniteSpringBean
    extends Object
    implements Ignite, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.SmartInitializingSingleton, org.springframework.context.ApplicationContextAware, Externalizable
    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 SmartInitializingSingleton interfaces, 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 ContextRefreshedEvent listener 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");
     

    See Also:
    Serialized Form