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.
- Add packages in Maven
- 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