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

io.microsphere.spring.config.env.annotation.JsonPropertySource 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.support.DefaultResourceComparator;
import io.microsphere.spring.config.env.support.JsonPropertySourceFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.AliasFor;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;
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 JSON {@link PropertySource} to Spring's Environment.
 * To be used in conjunction with {@link Configuration @Configuration} classes.
 *
 * @author Mercy
 * @see ResourcePropertySource
 * @see JsonPropertySourceFactory
 * @see MapPropertySource
 * @since 1.0.0
 */
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@ResourcePropertySource(factory = JsonPropertySourceFactory.class)
public @interface JsonPropertySource {

    /**
     * Indicate the name of this property source.
     *
     * @see 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 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 PropertySource}
     * 

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

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

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

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

For example, {@code "classpath:/com/myco/app.json"} *

Resource location wildcards (e.g. **/*.json) 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/*.json"}, suppose there are two resources named * "a.json" and "b.json" where two instances of {@link Resource} will be resolved, they are * the sources of {@link PropertySource}, thus it has to sort * them to indicate the order of {@link 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 JSON 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