Configuring incoming programs in the Web-autoconfig

Source: Internet
Author: User

Reference
Webx
Some of the environment variables run by the program will change as the machine changes, and AutoConfig will automatically load these variables in.
AutoConfig uses a set of configuration templates to generate specific configurations for different environments. Its core idea is to define a few mutable configurations as a template to generate specific configuration files from these templates when the AutoConfig is running.

    1. Add packages in Maven
    2. Meta-inf/autoconf/auto-config.xml is the AutoConfig configuration file.
<config>       <group>           < property name="Net.kiminotes.value" />               < property name= "alibaba.buc.acl.service.version" defaultvalue=" 2.0.0.daily " description=" HSF version of ACL service " />    </Group>       <script><generate template="CONFIG.PROPERTIES.VM" destfile="config.properties" charset=
     
       "Utf-8" />
     </script>   </config>   

The property here corresponds to a name->value, which also has the purpose of generating the. Properties file
Generate is to generate the target file. The variable that is replaced. Automatically changes to _

AutoConfig provides two ways to assign a value to a configuration variable first read from the Java properties file and the second is interactively edited.
AutoConfig first reads the antx.properties file for the current working directory, and if not, reads the $ {user.home}/ Antx.properties file, if this file does not exist, AutoConfig will start the interactive editor to request the user to enter the value of the configuration variable, if the value of the configuration variable is incomplete AutoConfig will immediately stop the configuration and throw an exception. If the location of the Java properties file is not in the AutoConfig default location, it can be configured by parameter autoconfig.userproperties. In a simple meantime, we create a new Java properties file Antx.properties in the current directory, which defines the value of the configuration variable ${Net_kiminotes_value}

Auto-config.xml

<?xml version= "1.0" encoding= "UTF-8"?><config>    <group name="Buc ACL">        < property name="Service.version" defaultvalue="2.0.0.daily" Description="HSF version of ACL service" />        < property name="Club.production" defaultvalue="Test" Description="production mode (run/test/debug)" />        < property name="App.name" defaultvalue="Club" description ="Buc app name" />        < property name="SystemID" defaultvalue="oplog00749_a597"  Description="SystemID" />    </Group>    <group name="Havana Club">        < property name="Club.output" defaultvalue="/home/admin/output/ Logs " description=" Log output path " />    </Group>    <script> <generate template= "CLUB.PROPERTIES.VM"  destfile=< Span class= "hljs-string" > "havana-club.properties"  charset= "UTF-8" /> <generate  template  = "WEB.XML.VM"  destfile  = "Web-inf/web.xml"  charset  =" UTF-8 "/>  << Span class= "Hljs-title" >generate  template  = " LOGBACK.XML.VM " destfile  =" web-inf/ Logback.xml " charset  =" UTF-8 "/>     </script></config>

Template
Club.properties.vm

service.version=${service_version}club.production=${club_production}club.buc.app.name=${app_name}club.output=${club_output}SystemId=${SystemId}

These parameters are loaded when the spring XML is read in

Spring.xml

<beanclass="Org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/> <beanclass="Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> < Property name="Ignoreunresolvableplaceholders"Value="true"/> < Property name="Locations"> <List> <value>classpath:club.properties</value> </List> </ Property> </bean> <--Incoming parameters--<beanID="Accesscontext" class="Com.web.AccessContext"> < Property name="AppName"Value="${app.name}"/>

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Configuring incoming programs in the Web-autoconfig

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.