Class SpringContextService

java.lang.Object
fr.paris.lutece.portal.service.spring.SpringContextService
All Implemented Interfaces:
PluginEventListener

public final class SpringContextService extends Object implements PluginEventListener
This class provides a way to use Spring Framework ligthweight containers offering IoC (Inversion of Control) features.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    getBean(String strName)
    Return an instance, which may be shared or independent, of the given bean name.
    static <T> List<T>
    getBeansOfType(Class<T> classDef)
    Returns a list of bean among all that implements a given interface or extends a given class
    static org.springframework.context.ApplicationContext
    Gets the application context
    static Object
    getPluginBean(String strPluginName, String strName)
    Deprecated.
    use getBean(String) instead
    static void
    init(javax.servlet.ServletContext servletContext)
    Initialize a global Application Context containing all beans (core + plugins) Now uses GenericApplicationContext for better performances.
    static boolean
    isBeanEnabled(String strBeanName)
    Indicates if a bean, referenced by its name, is part of an enabled plugin.
    void
    Process a plugin event
    static void
    Closes the Spring context

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getBean

      public static <T> T getBean(String strName)
      Return an instance, which may be shared or independent, of the given bean name. This method allows a Spring BeanFactory to be used as a replacement for the Singleton or Prototype design pattern.
      The bean is retreived from the main context defined in the WEB-INF/conf/core_context.xml.
      Type Parameters:
      T - the generic type
      Parameters:
      strName - The bean's name
      Returns:
      The instance of the bean
    • getPluginBean

      @Deprecated public static Object getPluginBean(String strPluginName, String strName)
      Deprecated.
      use getBean(String) instead
      Return an instance of the given bean name loaded by the a Spring BeanFactory. The bean is retreived from a plugin context defined in the WEB-INF/conf/plugins/[plugin_name]_context.xml.
      Parameters:
      strPluginName - The Plugin's name
      strName - The bean's name
      Returns:
      The instance of the bean
    • isBeanEnabled

      public static boolean isBeanEnabled(String strBeanName)
      Indicates if a bean, referenced by its name, is part of an enabled plugin. Per Lutece convention, the plugin is determined from the bean's name prefix. If no prefix is present, the bean is considered enabled.
      Parameters:
      strBeanName - The bean's name
      Returns:
      true if the bean is part of an enabled plugin, false otherwise
    • init

      public static void init(javax.servlet.ServletContext servletContext) throws LuteceInitException
      Initialize a global Application Context containing all beans (core + plugins) Now uses GenericApplicationContext for better performances. A wrong formatted file will not block block context to be built (without the file), but a wrong bean (i.e. cannot be instantiated) will cause a full context failure. Context is less "failure-friendly"
      Parameters:
      servletContext - The servlet context
      Throws:
      LuteceInitException - The lutece init exception
      Since:
      2.4
    • getContext

      public static org.springframework.context.ApplicationContext getContext()
      Gets the application context
      Returns:
      The application context
    • getBeansOfType

      public static <T> List<T> getBeansOfType(Class<T> classDef)
      Returns a list of bean among all that implements a given interface or extends a given class
      Type Parameters:
      T - The class type
      Parameters:
      classDef - The class type
      Returns:
      A list of beans
    • processPluginEvent

      public void processPluginEvent(PluginEvent event)
      Process a plugin event
      Specified by:
      processPluginEvent in interface PluginEventListener
      Parameters:
      event - The event to process
    • shutdown

      public static void shutdown()
      Closes the Spring context
      Since:
      5.1.0