Java tutorial
/** * Copyright 2013 Ben Navetta <ben@bennavetta.com> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.bennavetta.appsite.util; import javax.annotation.PostConstruct; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.commons.configuration.SystemConfiguration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import com.netflix.config.ConcurrentCompositeConfiguration; import com.netflix.config.ConcurrentMapConfiguration; import com.netflix.config.ConfigurationManager; @Configuration public class Config { @Autowired private DatastoreConfig datastoreConfig; @Bean public DatastoreConfig datastoreConfig() { return new DatastoreConfig(); } @PostConstruct public void setup() throws ConfigurationException { ConcurrentMapConfiguration systemConfig = new ConcurrentMapConfiguration(new SystemConfiguration()); ConcurrentMapConfiguration defaultConfig = new ConcurrentMapConfiguration( new PropertiesConfiguration("default-config.properties")); // datastore config would be concurrent because the datastore itself is ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration(); finalConfig.addConfiguration(datastoreConfig, "DatastoreConfig"); finalConfig.addConfiguration(defaultConfig, "DefaultConfig"); finalConfig.addConfiguration(systemConfig, "SystemConfig"); ConfigurationManager.install(finalConfig); } }