vaadin / multiplatform-runtime

4 stars 1 forks source link

Spring application.properties values not picket up by MPR Servlet #52

Open petrixh opened 5 years ago

petrixh commented 5 years ago

While working on a MPR migration project, we noticed that the application.properties values are not picked up by the MPRServlet.. Most notably, trying to set the application to production mode left the V8 runtime still in debug mode.

After some investigation a possible cause was found:

AbstractMprServlet#createDeploymentConfiguration(Properties initParameters)

looks for:

com.vaadin.flow.server.VaadinServlet flowServlet = (com.vaadin.flow.server.VaadinServlet)this.getServletContext().getAttribute(com.vaadin.flow.server.VaadinServlet.class.getName());
        if (flowServlet != null) {
            initParameters.setProperty("productionMode", Boolean.toString(flowServlet.getService().getDeploymentConfiguration().isProductionMode()));
        }

But in a spring-boot environment, the servlet is under a different key or loaded at a different time.

A bit of pre-debugging indicates that at the point where the MPR deployment configs are read, none of the entries in the ServletContext is an instance of com.vaadin.flow.server.VaadinServlet

Workaround for production mode (but not all application.properties settings) is to set the following System property:

com.vaadin.mpr.productionMode=true

So for instance:

java -jar -Dcom.vaadin.mpr.productionMode=true xxxx.war

Observed with: Vaadin 14.0.2 MPR 2.0.0

johannest commented 4 months ago

The issue seems to still reproduce with V23.4 and Spring Boot 2.7. If running the app with spring-boot:run the following workaround seems to help: mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dcom.vaadin.mpr.productionMode=true" -Pproduction