Title: OpenWebBeans FAQ
Internal configuration of OpenWebBeans can be done via: src/main/resources/META-INF/openwebbeans/openwebbeans.properties
All those files contain at single property configuration.ordinal
which defines their ‘importance’. Any setting from a property file with a higher configuration.ordinal will overwrite settings from one with a lower configuration.ordinal. The internally used configuration.ordinal values range from 1 to 100. The default value is 100.
This trick allows us to split OpenWebBeans in different modules which automatically change the container configuration if you put that jar on the classpath.
For overriding the default configuration with own settings simply put a META-INF/openwebbeans/openwebbeans.properties
file into your projects classpath (e.g. into a jar) and either use a configuration.ordinal
higher than 100 or leave it empty to get the default value of 100.
If you use OpenWebBeans as part of another project then you can assume that most of the values got tweaked by the integration regarding to the specific needs.
OpenWebBeans provide a set of Service Provider Interfaces and multiple different implementations a user can choose from.
You can choose the implementations you like to use for your situation by configuring them in META-INF/openwebbeans/openwebbeans.properties
.
Read more about our SPIs in OpenWebBeans SPI
The following configuration values can get tweaked to get tailor OWB to your specific needs.
Boolean values can either be true, or TRUE, or false, or FALSE.
OpenWebBeans enables the user to define the NormalScope handlers for specific scopes.
NormalScope handlers are used by OpenWebBeans' proxies to resolve the ‘Contextual Instance’. E.g. for a @SessionScoped User
injected into some other class, this is exactly the piece of code which goes into the current Http Session and gets the User instance from there. This class must extend org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler
and overwrite the Object getContextualInstance()
method.
This allows for more aggressive caching than with the generic NormalScopedBeanInterceptorHandler
which is the default. The default NormalScope handler will look up the Contextual Instance in the respective Context for each and every method invocation on the proxy.
But sometimes we can much more aggressively cache the instances.
E.g. for @ApplicationScoped
beans we can keep the contextual instance inside the proxy, making it as fast as a pure Java instance - but still gaining all the benefits of CDI!
For @RequestScoped
and @SessionScoped
we can use a NormalScope handler which caches the Contextual Instance in a ThreadLocal.
By default the following NormalScope handlers get used:
As you can see we use a prefix org.apache.webbeans.proxy.mapping.
followed by the fully qualified scope name as key. The value represents the fully qualified name of the handler class.
If you have a custom scope which spans a Request or longer then you can simply reuse the RequestScopedBeanInterceptorHandler
as shown in the following example:
OWB-1.5.x and later does not need any special module or filter to enable clustering. All that works out of the box as we now directly utilize the Servlet Session.
Add the clustering module to your project:
<dependency> <groupId>org.apache.openwebbeans</groupId> <artifactId>openwebbeans-clustering</artifactId> </dependency>
Register the FailOverFilter in your web.xml:
<filter> <filter-name>OWB FailOverFilter</filter-name> <filter-class>org.apache.webbeans.web.failover.FailOverFilter</filter-class> </filter> <filter-mapping> <filter-name>OWB FailOverFilter</filter-name> <servlet-name>Faces Servlet</servlet-name> </filter-mapping>
Add the following properties in your openwebbeans.properties:
configuration.ordinal=100 org.apache.webbeans.web.failover.issupportfailover=true org.apache.webbeans.web.failover.issupportpassivation=true
Register the FailOverFilter in your web.xml:
<filter> <filter-name>OWB FailOverFilter</filter-name> <filter-class>org.apache.webbeans.web.failover.FailOverFilter</filter-class> </filter> <filter-mapping> <filter-name>OWB FailOverFilter</filter-name> <servlet-name>Faces Servlet</servlet-name> </filter-mapping>