001/* 002 * Copyright 2002-2020 the original author or authors. 003 * 004 * Licensed under the Apache 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 * https://www.apache.org/licenses/LICENSE-2.0 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 017package org.springframework.beans.factory.support; 018 019import org.springframework.util.StringUtils; 020 021/** 022 * A simple holder for {@code BeanDefinition} property defaults. 023 * 024 * @author Mark Fisher 025 * @author Juergen Hoeller 026 * @since 2.5 027 * @see AbstractBeanDefinition#applyDefaults 028 */ 029public class BeanDefinitionDefaults { 030 031 private boolean lazyInit; 032 033 private int autowireMode = AbstractBeanDefinition.AUTOWIRE_NO; 034 035 private int dependencyCheck = AbstractBeanDefinition.DEPENDENCY_CHECK_NONE; 036 037 private String initMethodName; 038 039 private String destroyMethodName; 040 041 042 /** 043 * Set whether beans should be lazily initialized by default. 044 * <p>If {@code false}, the bean will get instantiated on startup by bean 045 * factories that perform eager initialization of singletons. 046 * @see AbstractBeanDefinition#setLazyInit 047 */ 048 public void setLazyInit(boolean lazyInit) { 049 this.lazyInit = lazyInit; 050 } 051 052 /** 053 * Return whether beans should be lazily initialized by default, i.e. not 054 * eagerly instantiated on startup. Only applicable to singleton beans. 055 * @return whether to apply lazy-init semantics ({@code false} by default) 056 */ 057 public boolean isLazyInit() { 058 return this.lazyInit; 059 } 060 061 /** 062 * Set the autowire mode. This determines whether any automagical detection 063 * and setting of bean references will happen. Default is AUTOWIRE_NO 064 * which means there won't be convention-based autowiring by name or type 065 * (however, there may still be explicit annotation-driven autowiring). 066 * @param autowireMode the autowire mode to set. 067 * Must be one of the constants defined in {@link AbstractBeanDefinition}. 068 * @see AbstractBeanDefinition#setAutowireMode 069 */ 070 public void setAutowireMode(int autowireMode) { 071 this.autowireMode = autowireMode; 072 } 073 074 /** 075 * Return the default autowire mode. 076 */ 077 public int getAutowireMode() { 078 return this.autowireMode; 079 } 080 081 /** 082 * Set the dependency check code. 083 * @param dependencyCheck the code to set. 084 * Must be one of the constants defined in {@link AbstractBeanDefinition}. 085 * @see AbstractBeanDefinition#setDependencyCheck 086 */ 087 public void setDependencyCheck(int dependencyCheck) { 088 this.dependencyCheck = dependencyCheck; 089 } 090 091 /** 092 * Return the default dependency check code. 093 */ 094 public int getDependencyCheck() { 095 return this.dependencyCheck; 096 } 097 098 /** 099 * Set the name of the default initializer method. 100 * <p>Note that this method is not enforced on all affected bean definitions 101 * but rather taken as an optional callback, to be invoked if actually present. 102 * @see AbstractBeanDefinition#setInitMethodName 103 * @see AbstractBeanDefinition#setEnforceInitMethod 104 */ 105 public void setInitMethodName(String initMethodName) { 106 this.initMethodName = (StringUtils.hasText(initMethodName) ? initMethodName : null); 107 } 108 109 /** 110 * Return the name of the default initializer method. 111 */ 112 public String getInitMethodName() { 113 return this.initMethodName; 114 } 115 116 /** 117 * Set the name of the default destroy method. 118 * <p>Note that this method is not enforced on all affected bean definitions 119 * but rather taken as an optional callback, to be invoked if actually present. 120 * @see AbstractBeanDefinition#setDestroyMethodName 121 * @see AbstractBeanDefinition#setEnforceDestroyMethod 122 */ 123 public void setDestroyMethodName(String destroyMethodName) { 124 this.destroyMethodName = (StringUtils.hasText(destroyMethodName) ? destroyMethodName : null); 125 } 126 127 /** 128 * Return the name of the default destroy method. 129 */ 130 public String getDestroyMethodName() { 131 return this.destroyMethodName; 132 } 133 134}