i am trying to use the Vaadin CDI Addon for my current project.
So far it works fine but i like to set the productionMode property to true instead of running in debug mode and without a web.xml.
It is stated in the
Vaadin CDI Tutorial that you are not allowed to use the @VaadinServletConfiguration annotation which makes sense because it requires an UI class, but it is also stated that:
“”
Custom Servlets
When customizing the Vaadin servlet, … , you simply need to extend com.vaadin.cdi.internal.VaadinCDIServlet instead ofcom.vaadin.servlet.VaadinServlet.
“”
But this did not help. Reviewing the code shows this:
[code]
com.vaadin.cdi.internal.ContextDeployer
…
private void registerServletToContext(ServletContext context) {
getLogger().info(“Registering VaadinServlet with CDIUIProvider”);
VaadinServlet vaadinServlet = new VaadinCDIServlet();
...
}
[/code]So therefore extending the cdi servlet will do nothing.
Is there currently a way to set the productionMode property using the CDI addon without a web.xml ?
BTW:
Im using Vaadin Version 8.1.5
and CDI-Addon Version 2.0.0
It is a solution that works for me and my project but maybe someone has a better idea.
You need to extend the
com.vaadin.cdi.server.VaadinCDIServlet
and add the annotation @WebServlet
. Here you can set your init parameter using the field initParams which expects an array of @WebInitParam
s.
There you have it, now you can set the productionMode and others. Keep in mind to add “/VAADIN/” to the urlPatterns. It is quite simple, but now you don’t need a web.xml for this case.
Here is an example:
@WebServlet(urlPatterns = { "/*", "/VAADIN/" }, name = "VaadinServlet", asyncSupported = true, initParams = {
@WebInitParam(name = "productionMode", value = "true"), @WebInitParam(name = "closeIdleSessions", value = "true") })
public class VaadinCDIServletAnnotated extends VaadinCDIServlet {
private static final long serialVersionUID = 1L;
}
Hi, you can also set production mode via a System Property.“vaadin.productionMode” and/or “com.vaadin.server.productionMode” should work, set the value to “true” if you want to enable it.