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:
- http://www.springframework.org
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T> TgetBean(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 classstatic org.springframework.context.ApplicationContextgetContext()Gets the application contextstatic ObjectgetPluginBean(String strPluginName, String strName)Deprecated.usegetBean(String)insteadstatic voidinit(javax.servlet.ServletContext servletContext)Initialize a global Application Context containing all beans (core + plugins) Now uses GenericApplicationContext for better performances.static booleanisBeanEnabled(String strBeanName)Indicates if a bean, referenced by its name, is part of an enabled plugin.voidprocessPluginEvent(PluginEvent event)Process a plugin eventstatic voidshutdown()Closes the Spring context
-
-
-
Method Detail
-
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.usegetBean(String)insteadReturn 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 namestrName- 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:
trueif the bean is part of an enabled plugin,falseotherwise
-
init
public static void init(javax.servlet.ServletContext servletContext) throws LuteceInitExceptionInitialize 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:
processPluginEventin interfacePluginEventListener- Parameters:
event- The event to process
-
shutdown
public static void shutdown()
Closes the Spring context- Since:
- 5.1.0
-
-