001 /** 002 * Copyright 2010-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.common.util.config.spring; 017 018 import java.util.Collections; 019 import java.util.List; 020 import java.util.Properties; 021 022 import org.kuali.common.util.config.service.ConfigService; 023 import org.kuali.common.util.spring.SpringUtils; 024 import org.springframework.beans.factory.annotation.Autowired; 025 import org.springframework.context.annotation.Bean; 026 import org.springframework.context.annotation.Configuration; 027 import org.springframework.context.annotation.Import; 028 import org.springframework.core.env.PropertySource; 029 030 /** 031 * 032 */ 033 @Configuration 034 @Import({ ConfigServiceConfig.class }) 035 public class BasicPropertySourceConfig { 036 037 @Autowired 038 ConfigServiceConfig utilConfigServiceConfig; 039 040 /** 041 * <p> 042 * Returns <code>Collections.emptyList()</code> by default. Override this method to pull in properties from other locations 043 * </p> 044 * 045 * Example configIds: 046 * 047 * <pre> 048 * org.kuali.common:kuali-sql 049 * org.kuali.common:kuali-util:scm 050 * org.kuali.common:kuali-util:metainf:mpx 051 * org.kuali.common:kuali-util:metainf:sql 052 * </pre> 053 */ 054 protected List<String> getConfigIds() { 055 return Collections.emptyList(); 056 } 057 058 /** 059 * <p> 060 * Returns an empty properties object by default. Override this method to inject properties that will override anything loaded from other locations 061 * </p> 062 */ 063 protected Properties getOverrides() { 064 return new Properties(); 065 } 066 067 /** 068 * Combine loaded properties, project properties, and system/environment properties into a <code>PropertySource<?></code> 069 */ 070 protected PropertySource<?> getPropertySource() { 071 ConfigService service = utilConfigServiceConfig.kualiUtilConfigService(); 072 List<String> configIds = getConfigIds(); 073 Properties properties = service.getProperties(configIds, getOverrides()); 074 return SpringUtils.getGlobalPropertySource(properties); 075 } 076 077 @Bean 078 public PropertySource<?> springPropertySource() { 079 return getPropertySource(); 080 } 081 082 }