Spring源码解析之AbstractBeanDefinition

primary

自动装配时当出现多个bean候选者时,将作为首选者。
对应XML配置中bean标签属性的primary。<bean id="xxx" class="xxx" primary="true">
对应注解:@org.springframework.context.annotation.Primary

initMethodName

初始化方法。
对应XML配置中bean标签属性的init-method。<bean id="xxx" class="xxx" init-method="xxx">
对应注解:@javax.annotation.PostConstruct

destoryMethodName

销毁方法。
对应XML配置中bean标签属性的destory-method。<bean id="xxx" class="xxx" destroy-method="xxx">
对应注解:@javax.annotation.PreDestroy

注解配置的案例:

@Service
@org.springframework.context.annotation.Primary
public class GuavaCache implements ICache {
    @Override
    public void greet() {
        // ...
    }
    @javax.annotation.PostConstruct
    public void init() {
        // ...
    }
    @javax.annotation.PreDestroy
    public void destroy() {
        // ...
    }
}

猜你喜欢

转载自blog.csdn.net/fomeiherz/article/details/103927164