声明为 Bean 时设置 VaadinServlet ProductonMode

Set VaadinServlet ProductonMode when declared as Bean

我们在更大的 OSGI (karaf 4) 应用程序中使用 Vaadin7,并使用蓝图声明了 VaadinServlet:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint default-activation="eager" xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<!-- Vaadin servlet serving static Vaadin resources -->
<service interface="javax.servlet.Servlet">
  <service-properties>
    <entry key="servlet-name" value="Vaadin Resources" />
    <entry key="alias" value="/VAADIN-ui" />
    <entry key="contextId" value="app-vaadin" />
  </service-properties>
  <bean class="com.vaadin.server.VaadinServlet" />
</service>

默认情况下,Vaadin 在调试模式下运行,并且有一个需要设置为 true 的 ProductionMode 设置。这可以作为上下文参数完成,但应用程序不使用 web.xml 文件。我试图将其设置为 bean 的 属性,但无法识别。

您可以扩展 VaadinServlet 并使用 VaadinServletConfiguration 注释。

来自文档:

Annotation for configuring subclasses of VaadinServlet. For a VaadinServlet class that has this annotation, the defined values are read during initialization and will be available using DeploymentConfiguration.getApplicationOrSystemProperty(String, String) as well as from specific methods in DeploymentConfiguration. Init params defined in web.xml or the @WebServlet annotation take precedence over values defined in this annotation.

你可以这样使用它:

@VaadinServletConfiguration(productionMode = false)
public class MyAppServlet extends VaadinServlet {
}