简体   繁体   English

在GWT中为开发和生产切换配置的最佳实践?

[英]Best Practice for switching Configuration for Development and Production in GWT?

When using GWT to configuration usually go into your web.xml. 使用GWT进行配置时,通常进入您的web.xml。 It is normal to have different settings for development and production environment. 为开发和生产环境设置不同的设置是正常的。 I know that I can also use my static html host page to pass parameters to GWT. 我知道我也可以使用我的静态html宿主页面将参数传递给GWT。

What is a best practice to switch my configuration between development and production? 在开发和生产之间切换配置的最佳实践是什么?

Simply create multiple properties file one for each enviroment to store the environment specific settings. 只需为每个环境创建一个属性文件即可存储特定于环境的设置。

Please have a look at below post to read the properties file at the time of server start-up. 请查看下面的文章,以在服务器启动时读取属性文件。


EDIT 编辑

I want to write a property in my static html file which will be read by gwt. 我想在我的静态html文件中写入一个属性,该属性将由gwt读取。 If the property is dev gwt should load test1.gwt.xml if property is prod gwt should load test2.gwt.xml . 如果属性为dev,则 gwt应加载test1.gwt.xml如果属性为prod,则 gwt应加载test2.gwt.xml

Sample code that is written in your welcome file ( index.jsp ). 编写在您的欢迎文件( index.jsp )中的示例代码。

<!-- Read environment attribute from application -->
<% String evn = application.getAttribute("env"); %>

<% if("prod".equalsIgnoreCase(env)) { %>
    <script type="text/javascript"
             src="myproject/test2.nocache.js"></script>
<% } else { %>
    <script type="text/javascript"
             src="myproject/test1.nocache.js"></script>
<% } %>

Note: You can use JavaServer Pages Standard Tag Library instead of Scriptlets. 注意:可以使用JavaServer Pages标准标记库代替Scriptlet。

In my experience, configuration in a Java application is generally best managed via property files. 以我的经验,通常最好通过属性文件来管理Java应用程序中的配置。 I might suggest the following: 我可能会建议以下内容:

  1. Create a property file to store this flag, for example: remoteLogging=true 创建一个属性文件来存储此标志,例如:remoteLogging = true

  2. Create a class on the server side that stores this type of configuration, for example SystemConfiguration with a Boolean property remoteLogging. 在服务器端创建一个用于存储这种配置类型的类,例如具有布尔属性remoteLogging的SystemConfiguration。

  3. At startup of the web application, inject the value of your properties into a singleton SystemConfiguration bean. 在启动Web应用程序时,将属性的值注入到Singleton SystemConfiguration bean中。

  4. On the client side, in your entry point (eg Application.java), in onModuleLoad() call the server to fetch the SystemConfiguration object. 在客户端,在入口点(例如Application.java)中,在onModuleLoad()中调用服务器以获取SystemConfiguration对象。

  5. Keep the SystemConfiguration object in memory on the client side, and whenever you need, check - for example if(systemConfig.getRemoteLogging()) { LOG.info("foo"); } 将SystemConfiguration对象保留在客户端的内存中,并在需要时检查-例如if(systemConfig.getRemoteLogging()) { LOG.info("foo"); } if(systemConfig.getRemoteLogging()) { LOG.info("foo"); }

Another path to go might be to have multiple versions of your .gwt.xml files (where remoteLogging log levels can be set), and have your build tool deploy the appropriate .gwt.xml file per environment. 另一个可行的方法可能是拥有多个版本的.gwt.xml文件(可以在其中设置remoteLogging日志级别),并让构建工具针对每个环境部署适当的.gwt.xml文件。 This would necessitate having building separately per environment though, which is generally not desirable. 但是,这将需要根据环境分别进行构建,这通常是不希望的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM