All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.microsphere.spring.config.env.annotation.YamlPropertySource Maven / Gradle / Ivy

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 io.microsphere.spring.config.env.annotation;

import io.microsphere.spring.config.context.annotation.ResourcePropertySource;
import io.microsphere.spring.config.env.ImmutableMapPropertySource;
import io.microsphere.spring.config.env.support.DefaultResourceComparator;
import io.microsphere.spring.config.env.support.YamlPropertySourceFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.AliasFor;
import org.springframework.core.io.Resource;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Comparator;

/**
 * The extension annotation of {ResourcePropertySource @ResourcePropertySource} providing a convenient and declarative
 * mechanism for adding a YAML {@link ImmutableMapPropertySource} to Spring's Environment.
 * To be used in conjunction with {@link Configuration @Configuration} classes.
 *
 * @author Mercy
 * @see ResourcePropertySource
 * @see ImmutableMapPropertySource
 * @see YamlPropertySourceFactory
 * @since 1.0.0
 */
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@ResourcePropertySource(factory = YamlPropertySourceFactory.class)
public @interface YamlPropertySource {

    /**
     * Indicate the name of this property source.
     *
     * @see org.springframework.core.env.PropertySource#getName()
     * @see Resource#getDescription()
     */
    @AliasFor(annotation = ResourcePropertySource.class)
    String name() default "";

    /**
     * It indicates the property source is auto-refreshed when the configuration is
     * changed.
     *
     * @return default value is false
     */
    @AliasFor(annotation = ResourcePropertySource.class)
    boolean autoRefreshed() default false;

    /**
     * Indicates current {@link org.springframework.core.env.PropertySource} is first order or not If specified ,
     * {@link #before()} and {@link #after()} will be ignored, or last order.
     *
     * @return default value is false
     */
    @AliasFor(annotation = ResourcePropertySource.class)
    boolean first() default false;

    /**
     * The relative order before specified {@link org.springframework.core.env.PropertySource}
     * 

* If not specified , current {@link org.springframework.core.env.PropertySource} will be added last. *

* If {@link #first()} specified , current attribute will be ignored. * * @return the name of {@link org.springframework.core.env.PropertySource}, default value is the empty string */ @AliasFor(annotation = ResourcePropertySource.class) String before() default ""; /** * The relative order after specified {@link org.springframework.core.env.PropertySource} *

* If not specified , current {@link org.springframework.core.env.PropertySource} will be added last. *

* If {@link #first()} specified , current attribute will be ignored. * * @return the name of {@link org.springframework.core.env.PropertySource}, default value is the empty string */ @AliasFor(annotation = ResourcePropertySource.class) String after() default ""; /** * Indicate the resource location(s) of the YAML file to be loaded. *

For example, {@code "classpath:/com/myco/app.yaml"} or {@code "classpath:/com/myco/app.yml"} * or {@code "file:/path/to/file.yaml"}. *

Resource location wildcards (e.g. **/*.yaml) also are permitted; *

${...} placeholders will be resolved against any/all property sources already * registered with the {@code Environment}. *

Each location will be added to the enclosing {@code Environment} as its own * property source, and in the order declared. */ @AliasFor(annotation = ResourcePropertySource.class) String[] value() default {}; /** * Indicate the resources to be sorted when {@link #value()} specifies the resource location wildcards *

For example, {@code "classpath:/com/myco/*.yaml"}, suppose there are two resources named * "a.yaml" and "b.yaml" where two instances of {@link Resource} will be resolved, they are * the sources of {@link org.springframework.core.env.PropertySource}, thus it has to sort * them to indicate the order of {@link org.springframework.core.env.PropertySource} that will be added to * the enclosing {@code Environment}. * *

Default is {@link DefaultResourceComparator} * * @see DefaultResourceComparator */ @AliasFor(annotation = ResourcePropertySource.class) Class> resourceComparator() default DefaultResourceComparator.class; /** * Indicate if a failure to find a {@link #value property resource} should be * ignored. *

{@code true} is appropriate if the YAML file is completely optional. *

Default is {@code false}. */ @AliasFor(annotation = ResourcePropertySource.class) boolean ignoreResourceNotFound() default false; /** * A specific character encoding for the given resources. *

Default is "UTF-8" */ @AliasFor(annotation = ResourcePropertySource.class) String encoding() default "UTF-8"; }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy