Differences
This shows you the differences between two versions of the page.
vaadin_7_production_mode [2014/03/11 13:56] |
vaadin_7_production_mode [2021/04/05 11:23] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Vaadin 7 Production Mode ====== | ||
+ | In a normal environment you would have at least 2 environments to deploy your Vaadin application to, your own development environment and the production environment. Vaadin offers a production mode where things are optimized for performance. In production mode the debug window cannot be enabled via the url, Parameter // | ||
+ | ===== Enable Production Mode ===== | ||
+ | |||
+ | ==== Annotations ==== | ||
+ | You can annotate your servlet with the following code to set the productionMode to true (or false). | ||
+ | |||
+ | @VaadinServletConfiguration(productionMode = true, ui = DemoUi.class) | ||
+ | |||
+ | ==== WAR File - web.xml ==== | ||
+ | Normally the production mode is set via the //web.xml// file in the web application archive. | ||
+ | |||
+ | <sxh xml> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | The con side of this approach is that regardless of the environment the production mode is always the same as declared in the //web.xml// file. | ||
+ | </ | ||
+ | |||
+ | ==== VM Argument ==== | ||
+ | Vaadin supports setting the production mode via a VM argument. The naming of the argument is as follows: | ||
+ | |||
+ | <vaadin servlet base package name> | ||
+ | |||
+ | If the default VaadinServlet (package // | ||
+ | |||
+ | com.vaadin.server.productionMode=true|false | ||
+ | |||
+ | If a custom VaadinServlet class is declared in the //web.xml// file the package name of the custom class must be used. | ||
+ | |||
+ | ==== Programmatically Settings ==== | ||
+ | If the above described ways to the set the production mode don't suffice then there is also the option to set the production mode programmatically, | ||
+ | |||
+ | For this a custom VaadinServlet must be created and specified in the //web.xml// file. In the CustomVaadinServlet class the method // | ||
+ | |||
+ | <sxh java> | ||
+ | public class CustomVaadinServlet extends VaadinServlet { | ||
+ | |||
+ | @Override | ||
+ | protected DeploymentConfiguration createDeploymentConfiguration(Properties initParameters) { | ||
+ | Boolean prodMode = getProductionMode(); | ||
+ | initParameters.setProperty(" | ||
+ | | ||
+ | DeploymentConfiguration configuration = super.createDeploymentConfiguration(initParameters); | ||
+ | // don't add init parm productionMode after construction because productionMode in | ||
+ | // deployment configuration has already been evaluated and is only evaluated in constructor | ||
+ | return configuration; | ||
+ | } | ||
+ | |||
+ | private Boolean getProductionMode() { | ||
+ | boolean prodMode; | ||
+ | ... | ||
+ | return prodMode; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | The //super// call to the method will return an object of the class // | ||
+ | |||
+ | {{tag> |