|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2020 the original author or authors. |
| 2 | + * Copyright 2002-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -180,14 +180,23 @@ private SpringContainedBean<?> createBean(
|
180 | 180 |
|
181 | 181 | try {
|
182 | 182 | if (lifecycleOptions.useJpaCompliantCreation()) {
|
183 |
| - Object bean = this.beanFactory.autowire(beanType, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false); |
184 |
| - this.beanFactory.autowireBeanProperties(bean, AutowireCapableBeanFactory.AUTOWIRE_NO, false); |
185 |
| - this.beanFactory.applyBeanPropertyValues(bean, name); |
186 |
| - bean = this.beanFactory.initializeBean(bean, name); |
187 |
| - return new SpringContainedBean<>(bean, beanInstance -> this.beanFactory.destroyBean(name, beanInstance)); |
| 183 | + if (this.beanFactory.containsBean(name)) { |
| 184 | + Object bean = this.beanFactory.autowire(beanType, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false); |
| 185 | + this.beanFactory.autowireBeanProperties(bean, AutowireCapableBeanFactory.AUTOWIRE_NO, false); |
| 186 | + this.beanFactory.applyBeanPropertyValues(bean, name); |
| 187 | + bean = this.beanFactory.initializeBean(bean, name); |
| 188 | + return new SpringContainedBean<>(bean, beanInstance -> this.beanFactory.destroyBean(name, beanInstance)); |
| 189 | + } |
| 190 | + else { |
| 191 | + return new SpringContainedBean<>( |
| 192 | + this.beanFactory.createBean(beanType, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false), |
| 193 | + this.beanFactory::destroyBean); |
| 194 | + } |
188 | 195 | }
|
189 | 196 | else {
|
190 |
| - return new SpringContainedBean<>(this.beanFactory.getBean(name, beanType)); |
| 197 | + return (this.beanFactory.containsBean(name) ? |
| 198 | + new SpringContainedBean<>(this.beanFactory.getBean(name, beanType)) : |
| 199 | + new SpringContainedBean<>(this.beanFactory.getBean(beanType))); |
191 | 200 | }
|
192 | 201 | }
|
193 | 202 | catch (BeansException ex) {
|
|
0 commit comments