1/** 2 * Return an instance, which may be shared or independent, of the specified bean.
3 * @param name the name of the bean to retrieve
4 * @param requiredType the required type of the bean to retrieve
5 * @param args arguments to use when creating a bean instance using explicit arguments
6 * (only applied when creating a new instance as opposed to retrieving an existing one)
7 * @param typeCheckOnly whether the instance is obtained for a type check,
8 * not for actual use
9 * @return an instance of the bean
10 * @throws BeansException if the bean could not be created
11*/ 12 @SuppressWarnings("unchecked")
13protected T doGetBean(
14final String name, final Class requiredType, final Object[] args, boolean typeCheckOnly)
15throws BeansException {
16 17final String beanName = transformedBeanName(name);
18 Object bean;
19 20// Eagerly check singleton cache for manually registered singletons. 21 Object sharedInstance = getSingleton(beanName);
22if (sharedInstance != null && args == null) {
23if (logger.isDebugEnabled()) {
24if (isSingletonCurrentlyInCreation(beanName)) {
25 logger.debug("Returning eagerly cached instance of singleton bean '" + beanName +
26 "' that is not fully initialized yet - a consequence of a circular reference");
27 }
28else {
29 logger.debug("Returning cached instance of singleton bean '" + beanName + "'");
30 }
31 }
32 bean = getObjectForBeanInstance(sharedInstance, name, beanName, null);
33 }
34 35else {
36// Fail if we're already creating this bean instance:
37// We're assumably within a circular reference. 38if (isPrototypeCurrentlyInCreation(beanName)) {
39thrownew BeanCurrentlyInCreationException(beanName);
40 }
41 42// Check if bean definition exists in this factory. 43 BeanFactory parentBeanFactory = getParentBeanFactory();
44if (parentBeanFactory != null && !containsBeanDefinition(beanName)) {
45// Not found -> check parent. 46 String nameToLookup = originalBeanName(name);
47if (args != null) {
48// Delegation to parent with explicit args. 49return (T) parentBeanFactory.getBean(nameToLookup, args);
50 }
51else {
52// No args -> delegate to standard getBean method. 53return parentBeanFactory.getBean(nameToLookup, requiredType);
54 }
55 }
56 57if (!typeCheckOnly) {
58 markBeanAsCreated(beanName);
59 }
60 61try {
62final RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);
63 checkMergedBeanDefinition(mbd, beanName, args);
64 65// Guarantee initialization of beans that the current bean depends on. 66 String[] dependsOn = mbd.getDependsOn();
67if (dependsOn != null) {
68for (String dep : dependsOn) {
69if (isDependent(beanName, dep)) {
70thrownew BeanCreationException(mbd.getResourceDescription(), beanName,
71 "Circular depends-on relationship between '" + beanName + "' and '" + dep + "'");
72 }
73 registerDependentBean(dep, beanName);
74 getBean(dep);
75 }
76 }
77 78// Create bean instance. 79if (mbd.isSingleton()) {
80 sharedInstance = getSingleton(beanName, new ObjectFactory
1/** 2 * Actually create the specified bean. Pre-creation processing has already happened
3 * at this point, e.g. checking {@code postProcessBeforeInstantiation} callbacks.
4 *
Differentiates between default bean instantiation, use of a
5 * factory method, and autowiring a constructor.
6 * @param beanName the name of the bean
7 * @param mbd the merged bean definition for the bean
8 * @param args explicit arguments to use for constructor or factory method invocation
9 * @return a new instance of the bean
10 * @throws BeanCreationException if the bean could not be created
11 * @see #instantiateBean
12 * @see #instantiateUsingFactoryMethod
13 * @see #autowireConstructor
14*/ 15protected Object doCreateBean(final String beanName, final RootBeanDefinition mbd, final Object[] args)
16throws BeanCreationException {
17 18// Instantiate the bean. 19 BeanWrapper instanceWrapper = null;
20if (mbd.isSingleton()) {
21 instanceWrapper = this.factoryBeanInstanceCache.remove(beanName);
22 }
23if (instanceWrapper == null) {
24 instanceWrapper = createBeanInstance(beanName, mbd, args);
25 }
26final Object bean = (instanceWrapper != null ? instanceWrapper.getWrappedInstance() : null);
27 Class> beanType = (instanceWrapper != null ? instanceWrapper.getWrappedClass() : null);
28 mbd.resolvedTargetType = beanType;
29 30// Allow post-processors to modify the merged bean definition. 31synchronized (mbd.postProcessingLock) {
32if (!mbd.postProcessed) {
33try {
34 applyMergedBeanDefinitionPostProcessors(mbd, beanType, beanName);
35 }
36catch (Throwable ex) {
37thrownew BeanCreationException(mbd.getResourceDescription(), beanName,
38 "Post-processing of merged bean definition failed", ex);
39 }
40 mbd.postProcessed = true;
41 }
42 }
43 44// Eagerly cache singletons to be able to resolve circular references
45// even when triggered by lifecycle interfaces like BeanFactoryAware. 46boolean earlySingletonExposure = (mbd.isSingleton() && this.allowCircularReferences &&
47 isSingletonCurrentlyInCreation(beanName));
48if (earlySingletonExposure) {
49if (logger.isDebugEnabled()) {
50 logger.debug("Eagerly caching bean '" + beanName +
51 "' to allow for resolving potential circular references");
52 }
53 addSingletonFactory(beanName, new ObjectFactory() {
54 @Override
55public Object getObject() throws BeansException {
56return getEarlyBeanReference(beanName, mbd, bean);
57 }
58 });
59 }
60 61// Initialize the bean instance. 62 Object exposedObject = bean;
63try {
64 populateBean(beanName, mbd, instanceWrapper);
65if (exposedObject != null) {
66 exposedObject = initializeBean(beanName, exposedObject, mbd);
67 }
68 }
69catch (Throwable ex) {
70if (ex instanceof BeanCreationException && beanName.equals(((BeanCreationException) ex).getBeanName())) {
71throw (BeanCreationException) ex;
72 }
73else {
74thrownew BeanCreationException(
75 mbd.getResourceDescription(), beanName, "Initialization of bean failed", ex);
76 }
77 }
78 79if (earlySingletonExposure) {
80 Object earlySingletonReference = getSingleton(beanName, false);
81if (earlySingletonReference != null) {
82if (exposedObject == bean) {
83 exposedObject = earlySingletonReference;
84 }
85elseif (!this.allowRawInjectionDespiteWrapping && hasDependentBean(beanName)) {
86 String[] dependentBeans = getDependentBeans(beanName);
87 Set actualDependentBeans = new LinkedHashSet(dependentBeans.length);
88for (String dependentBean : dependentBeans) {
89if (!removeSingletonIfCreatedForTypeCheckOnly(dependentBean)) {
90 actualDependentBeans.add(dependentBean);
91 }
92 }
93if (!actualDependentBeans.isEmpty()) {
94thrownew BeanCurrentlyInCreationException(beanName,
95 "Bean with name '" + beanName + "' has been injected into other beans [" +
96 StringUtils.collectionToCommaDelimitedString(actualDependentBeans) +
97 "] in its raw version as part of a circular reference, but has eventually been " +
98 "wrapped. This means that said other beans do not use the final version of the " +
99 "bean. This is often the result of over-eager type matching - consider using " +
100 "'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.");
101 }
102 }
103 }
104 }
105106// Register bean as disposable.107try {
108 registerDisposableBeanIfNecessary(beanName, bean, mbd);
109 }
110catch (BeanDefinitionValidationException ex) {
111thrownew BeanCreationException(
112 mbd.getResourceDescription(), beanName, "Invalid destruction signature", ex);
113 }
114115return exposedObject;
116 }
创建Web工程,使用eclipse ee创建maven web工程 1.右键项目,选择Project Facets,点击Convert to faceted from 2.更改Dynamic Web Module的Version为2.5.(3.0为Java7的,Tomcat6不支持). 如果提示错误,可能需要在Java Compiler设置Compiler compl
最近一直在看python的document,打算在基础方面重点看一下python的keyword、Build-in Function、Build-in Constants、Build-in Types、Build-in Exception这四个方面,其实在看的时候发现整个《The Python Standard Library》章节都是很不错的,其中描述了很多不错的主题。先把Build-in Fu
学习函数式编程
package base;
import java.text.DecimalFormat;
public class Main {
public static void main(String[] args) {
// Integer a = 4;
// Double aa = (double)a / 100000;
// Decimal
Java中的泛型的使用:1.普通的泛型使用
在使用类的时候后面的<>中的类型就是我们确定的类型。
public class MyClass1<T> {//此处定义的泛型是T
private T var;
public T getVar() {
return var;
}
public void setVa