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

top.osjf.sdk.spring.beans.BeanProperty Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
/*
 * Copyright 2024-? the original author or authors.
 *
 * 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
 *
 *      https://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 top.osjf.sdk.spring.beans;

import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.AliasFor;
import top.osjf.sdk.spring.annotation.Sdk;

import java.lang.annotation.*;

/**
 * Dynamically construct annotation identifiers for {@link BeanDefinition},
 * which include some essential attributes related to spring beans and also
 * provide some default values.
 *
 * 

They inherit all related attributes of {@link Bean} and can be used * directly as {@link Bean}. * *

The basic purpose is to serve as a secondary attribute for special * bean registration services, such as setting properties for proxy beans * annotated with {@link Sdk}. * * @author zhangpengfei * @see BeanPropertyUtils * @since 1.0.0 */ @Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @Bean public @interface BeanProperty { /** * Constant for the default scope name: {@code ""}, equivalent to singleton * status unless overridden from a parent bean definition (if applicable). */ String SCOPE_DEFAULT = ""; /** * Role hint indicating that a {@code BeanDefinition} is a major part * of the application. Typically corresponds to a user-defined bean. */ int ROLE_APPLICATION = 0; /** * @return {@code org.springframework.context.annotation.Bean#value()} */ @AliasFor(annotation = Bean.class) String[] value() default {}; /** * @return {@code org.springframework.context.annotation.Bean#name()} */ @AliasFor(annotation = Bean.class) String[] name() default {}; /** * @return {@code org.springframework.context.annotation.Bean#autowire()} * @deprecated copy from Bean#autowire() explain as of 5.1, since {@code @Bean} factory method * argument resolution and {@code @Autowired} processing supersede name/type-based bean property * injection. */ @Deprecated @AliasFor(annotation = Bean.class) Autowire autowire() default Autowire.NO; /** * @return {@code org.springframework.context.annotation.Bean#autowireCandidate()} */ @AliasFor(annotation = Bean.class) boolean autowireCandidate() default true; /** * If you want to use this annotation as a replacement for {@link Bean}, * then this property will still be effective in its usage with {@link Bean}, * but if you want to use it together with {@link Sdk}, it is invalid because * the proxy class is fixed. * * @return {@code org.springframework.context.annotation.Bean#initMethod()} */ @AliasFor(annotation = Bean.class) String initMethod() default ""; /** * If you want to use this annotation as a replacement for {@link Bean}, * then this property will still be effective in its usage with {@link Bean}, * but if you want to use it together with {@link Sdk}, it is invalid because * the proxy class is fixed. * * @return {@code org.springframework.context.annotation.Bean#destroyMethod()} */ @AliasFor(annotation = Bean.class) String destroyMethod() default AbstractBeanDefinition.INFER_METHOD; /** * The scope of the spring container bean. * The default is {@link AbstractBeanDefinition#SCOPE_DEFAULT},Equivalent to * {@link AbstractBeanDefinition#SCOPE_SINGLETON} * * @return Returns the scope range,defaults to singleton. * @see BeanDefinitionBuilder#setScope(String) * @see ConfigurableBeanFactory#SCOPE_PROTOTYPE * @see ConfigurableBeanFactory#SCOPE_SINGLETON * @see org.springframework.beans.factory.config.Scope * @see org.springframework.context.annotation.Scope * @see org.springframework.web.context.annotation.RequestScope * @see org.springframework.web.context.annotation.SessionScope * @see org.springframework.web.context.annotation.ApplicationScope */ String scope() default SCOPE_DEFAULT; /** * Set the role hint for this {@code BeanDefinition}. *

The explanation comes from {@link AbstractBeanDefinition#setRole(int)}}. *

{@code role = 0} *

Role hint indicating that a {@code BeanDefinition} is a major part * of the application. Typically corresponds to a user-defined bean. *

{@code role = 1} *

Role hint indicating that a {@code BeanDefinition} is a supporting * part of some larger configuration, typically an outer * {@link org.springframework.beans.factory.parsing.ComponentDefinition}. * {@code SUPPORT} beans are considered important enough to be aware * of when looking more closely at a particular * {@link org.springframework.beans.factory.parsing.ComponentDefinition}, * but not when looking at the overall configuration of an application. *

{@code role = 2} *

Role hint indicating that a {@code BeanDefinition} is providing an * entirely background role and has no relevance to the end-user. This hint is * used when registering beans that are completely part of the internal workings * of a {@link org.springframework.beans.factory.parsing.ComponentDefinition}. *

The explanation comes from {@link BeanDefinition}}. *

Generally, the proxy object automatically generated by SDK is user-defined * on the application side, that is, {@code role = 0}, which can * be set according to one's own needs. * * @return A bean lifeStyle role type,defaults user-yourself define. * @see org.springframework.context.annotation.Role * @see BeanDefinition#ROLE_APPLICATION * @see BeanDefinition#ROLE_INFRASTRUCTURE * @see BeanDefinition#ROLE_SUPPORT */ int role() default ROLE_APPLICATION; /** * Set whether this bean should be lazily initialized. *

If {@code false}, the bean will get instantiated on startup by bean * factories that perform eager initialization of singletons. *

The explanation comes from {@link AbstractBeanDefinition#setLazyInit(boolean)}. * * @return A bean decide whether to lazily load,defaults not. * @see org.springframework.context.annotation.Lazy */ boolean lazyInit() default false; /** * Set a human-readable description of this bean definition. *

The explanation comes from {@link AbstractBeanDefinition#setDescription(String)}. * * @return A bean with its description content,defaults blank. * @see org.springframework.context.annotation.Description */ String description() default ""; }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy