You can use Spring to make Java Beans available to your customized Workflow actions and expressions. The Spring context is loaded at startup time and is shut down when the server is shut down. The Spring XML configuration can refer to the Workflow Server's Unified API connection, using the same name ("connection") as in the CAE. An action or expression may implement the interface com.coremedia.cap.workflow.plugin.CapConnectionAware. If it does so, the connection is injected before the action is executed or the expression is evaluated for the first time.
The Spring XML file can refer to properties defined in
WEB-INF/application.properties
,
WEB-INF/properties/corem/workflowserver.properties
, or in any property file under
WEB-INF/config/workflowserver/spring/*.properties,
using Spring's property
placeholder syntax: ${propertyname}
. The property's value is inserted when the
application context is loaded.
If you want the property to be updated when the property file changes, you can use an
alternative syntax: #{propertyname}
. This causes all affected bean property
setters to be invoked whenever the property file is reloaded and the value has changed.
In order to use a bean in your action or expression proceed as follows:
Make a Spring
ApplicationContext
available to the Workflow Server. To do so, configure a SpringContextManager in theworkflowserver.properties
file:
workflow.server.managers.springcontext.class= com.coremedia.workflow.common.util.SpringContextManager
Configure the location of the main Spring application context file, for example :
workflow.server.managers.springcontext.configurations= config/workflowserver/spring/applicationContext.xml
Import at least the minimum bean set by defining an import to
classpath:/framework/spring/workflowserver.xml
.Configure the beans you want to use in any of the configured configuration files. If you want to load beans defined in other configuration files than
applicationContext.xml
, you have to define imports to these files.Let your customized actions, expressions or Boolean expressions extend com.coremedia.workflow.common.util.SpringAwareAction, com.coremedia.workflow.common.util.SpringAwareExpression and com.coremedia.workflow.common.util.SpringAwareBooleanExpression respectively.
Get the Bean inside your customized code using the
getBean()
method, for example use
protected ActionResult execute(Process process) { InboxFactory inboxes = (InboxFactory) getBean("inboxFactory"); … }
The configured beans may implement the common Spring interfaces InitializingBean
and DisposableBean
in order to receive life cycle events from the context
manager. Additionally, the beans may implement the interface
com.coremedia.workflow.common.util.WorkflowServerLifecycleAware,
if they want to initiate asynchronous operations. Such operations may start after the method
workflowServerStart()
is called and must be completed before the method
workflowServerStop()
returns. Only singleton beans receive these callbacks and
only if they implement the given interface.