Class SpringApplicationService

java.lang.Object
co.ecg.alpaca.toolkit.service.SpringApplicationService
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware

@Service public class SpringApplicationService extends Object implements org.springframework.context.ApplicationContextAware
Wrapper to always return a reference to the Spring Application Context from within non-Spring enabled beans. Unlike Spring MVC's WebApplicationContextUtils we do not need a reference to the Servlet context for this. All we need is for this bean to be initialized during application startup.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    getBean(Class<T> beanClass)
    This is about the same as context.getBean(beanClass), except it has its own static handle to the Spring context, so calling this method statically will give access to the beans by class in the Spring application context.
    static Object
    getBean(String beanName)
    This is about the same as context.getBean("beanName"), except it has its own static handle to the Spring context, so calling this method statically will give access to the beans by name in the Spring application context.
    static boolean
    This method checks if a Spring Application Context has been created.
    void
    setApplicationContext(org.springframework.context.ApplicationContext context)
    This method is called from within the ApplicationContext once it is done starting up, it will stick a reference to itself into this bean.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SpringApplicationService

      public SpringApplicationService()
  • Method Details

    • getBean

      public static Object getBean(String beanName)
      This is about the same as context.getBean("beanName"), except it has its own static handle to the Spring context, so calling this method statically will give access to the beans by name in the Spring application context. As in the context.getBean("beanName") call, the caller must cast to the appropriate target class. If the bean does not exist, then a Runtime error will be thrown.
      Parameters:
      beanName - the name of the bean to get.
      Returns:
      an Object reference to the named bean.
    • getBean

      public static <T> T getBean(Class<T> beanClass)
      This is about the same as context.getBean(beanClass), except it has its own static handle to the Spring context, so calling this method statically will give access to the beans by class in the Spring application context. If the bean does not exist, then a Runtime error will be thrown.
      Parameters:
      beanClass - the class of the bean to get.
      Returns:
      an Object reference to the named bean.
    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext context) throws org.springframework.beans.BeansException
      This method is called from within the ApplicationContext once it is done starting up, it will stick a reference to itself into this bean.
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Parameters:
      context - a reference to the ApplicationContext.
      Throws:
      org.springframework.beans.BeansException
    • hasApplicationContext

      public static boolean hasApplicationContext()
      This method checks if a Spring Application Context has been created.
      Returns:
      True if the context is not null.