|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.vaadin.Application
org.dellroad.stuff.vaadin.ContextApplication
org.dellroad.stuff.vaadin.SpringContextApplication
public abstract class SpringContextApplication
Vaadin application implementation that manages an associated Spring WebApplicationContext.
Each Vaadin application instance is given its own Spring application context, and all such
application contexts share the same parent context, which is the one associated with the overal servlet web context
(i.e., the one created by Spring's ContextLoaderListener).
A context is created when a new Vaadin application instance is initialized, and destroyed when it is closed.
This setup is analogous to how Spring's DispatcherServlet
creates per-servlet application contexts that are children of the overall servlet web context.
For each Vaadin application com.example.FooApplication that subclasses this class, there should exist an XML
file named FooApplication.xml in the WEB-INF/ directory that defines the per-Vaadin application Spring
application context (this naming scheme can be overriden).
This SpringContextApplication instance can itself be exposed in and configured by the associated Spring
application context by using a bean definition invoking the static factory method ContextApplication.get():
Note however that Spring will autowire this bean based on the type<bean id="myVaadinApplication" class="org.dellroad.stuff.vaadin.ContextApplication" factory-method="get"/>
ContextApplication rather than it's actual type.
To make Spring aware of your Vaadin application's actual type, you can add a custom factory method to your application class:
public class MyVaadinApplication extends SpringContextApplication {
public MyApplication get() {
return ContextApplication.get(MyApplication.class);
}
}
<bean id="myVaadinApplication" class="com.example.MyApplication" factory-method="get"/>
@VaadinConfigurable Beans
It is also possible to configure beans outside of this application context using AOP, so that any invocation of
new FooBar(), where the class FooBar is marked @VaadinConfigurable,
will automagically cause the new FooBar object to be configured by the application context associated with
the currently running application instance. In effect, this does for
Vaadin application beans what Spring's @Configurable
does for regular beans.
Note however that Spring destroy methods
will not be invoked on application close for these beans, since their lifecycle is controlled outside of the
Spring application context (this is also the case with
@Configurable beans). Instead, these beans
can register as a ContextApplication.CloseListener for shutdown notification.
For the this annotation to do anything, @VaadinConfigurable classes must be woven
(either at build time or runtime) using the
AspectJ compiler with the
VaadinConfigurableAspect aspect (included in the dellroad-stuff JAR file).
ContextApplication.get(),
ContextApplicationFactoryBean,
Example Code on GitHub,
Serialized Form| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class org.dellroad.stuff.vaadin.ContextApplication |
|---|
ContextApplication.CloseEvent, ContextApplication.CloseListener |
| Nested classes/interfaces inherited from class com.vaadin.Application |
|---|
Application.ApplicationError, Application.CustomizedSystemMessages, Application.SystemMessages, Application.UserChangeEvent, Application.UserChangeListener, Application.WindowAttachEvent, Application.WindowAttachListener, Application.WindowDetachEvent, Application.WindowDetachListener |
| Nested classes/interfaces inherited from interface com.vaadin.terminal.URIHandler |
|---|
URIHandler.ErrorEvent |
| Field Summary |
|---|
| Fields inherited from class org.dellroad.stuff.vaadin.ContextApplication |
|---|
DEFAULT_NOTIFICATION_DELAY, log |
| Constructor Summary | |
|---|---|
SpringContextApplication()
|
|
| Method Summary | |
|---|---|
protected void |
destroySpringApplication()
Perform any application-specific shutdown work. |
static SpringContextApplication |
get()
Get the SpringContextApplication instance associated with the current thread or throw an exception if there is none. |
ConfigurableWebApplicationContext |
getApplicationContext()
Get this instance's associated Spring application context. |
protected String |
getApplicationName()
Get the name for this application. |
protected void |
initApplication()
Initializes the associated ConfigurableWebApplicationContext. |
protected abstract void |
initSpringApplication(ConfigurableWebApplicationContext context)
Initialize the application. |
protected void |
onRefresh(ApplicationContext context)
Perform any application-specific work after a successful application context refresh. |
protected void |
postProcessWebApplicationContext(ConfigurableWebApplicationContext context)
Post-process the given WebApplicationContext after initial creation but before the initial
refresh(). |
| Methods inherited from class org.dellroad.stuff.vaadin.ContextApplication |
|---|
addListener, close, currentApplication, currentApplication, currentRequest, currentResponse, doOnRequestEnd, doOnRequestStart, get, getErrorMessage, getNotificationDelay, init, invoke, invokeLater, onRequestEnd, onRequestStart, removeListener, showError, showError, terminalError |
| Methods inherited from class com.vaadin.Application |
|---|
addListener, addListener, addListener, addResource, addWindow, getContext, getErrorHandler, getLocale, getLogoutURL, getMainWindow, getProperty, getPropertyNames, getRelativeLocation, getSystemMessages, getTheme, getURL, getUser, getVersion, getWindow, getWindows, handleURI, isRunning, removeListener, removeListener, removeListener, removeResource, removeWindow, setErrorHandler, setLocale, setLogoutURL, setMainWindow, setTheme, setUser, start |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SpringContextApplication()
| Method Detail |
|---|
public ConfigurableWebApplicationContext getApplicationContext()
public static SpringContextApplication get()
SpringContextApplication instance associated with the current thread or throw an exception if there is none.
Works just like ContextApplication.get() but returns this narrower type.
SpringContextApplication associated with the current thread
IllegalStateException - if the current thread is not servicing a Vaadin web request
or the current Vaadin Application is not a SpringContextApplicationprotected final void initApplication()
ConfigurableWebApplicationContext.
initApplication in class ContextApplicationprotected abstract void initSpringApplication(ConfigurableWebApplicationContext context)
SpringContextApplication must implement this method.
context - the associated WebApplicationContext just created and refresheddestroySpringApplication()protected void destroySpringApplication()
WebApplicationContext have both been closed.
The implementation in SpringContextApplication does nothing. Subclasses may override as necessary.
Note that if a SpringContextApplication instance is exposed in the application context and configured
with a Spring destroy method, then that
method will also be invoked when the application is closed. In such cases overriding this method is not necessary.
initSpringApplication(org.springframework.web.context.ConfigurableWebApplicationContext)protected void postProcessWebApplicationContext(ConfigurableWebApplicationContext context)
WebApplicationContext after initial creation but before the initial
refresh().
The implementation in SpringContextApplication does nothing. Subclasses may override as necessary.
context - the associated WebApplicationContext just refreshedonRefresh(org.springframework.context.ApplicationContext),
ConfigurableApplicationContext.refresh()protected void onRefresh(ApplicationContext context)
The implementation in SpringContextApplication does nothing. Subclasses may override as necessary.
context - the associated WebApplicationContext just refreshedpostProcessWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext),
ConfigurableApplicationContext.refresh()protected String getApplicationName()
WEB-INF/ that
defines the Spring application context associated with this instance.
The implementation in SpringContextApplication returns this instance's class'
simple name.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||