|
32 | 32 | import org.springframework.asm.Opcodes;
|
33 | 33 | import org.springframework.asm.Type;
|
34 | 34 | import org.springframework.beans.BeanInstantiationException;
|
| 35 | +import org.springframework.beans.BeanUtils; |
35 | 36 | import org.springframework.cglib.core.ReflectUtils;
|
36 | 37 | import org.springframework.core.NativeDetector;
|
37 | 38 | import org.springframework.data.mapping.FactoryMethod;
|
@@ -159,8 +160,7 @@ private EntityInstantiator createEntityInstantiator(PersistentEntity<?, ?> entit
|
159 | 160 | * @return
|
160 | 161 | */
|
161 | 162 | protected EntityInstantiator doCreateEntityInstantiator(PersistentEntity<?, ?> entity) {
|
162 |
| - return new EntityInstantiatorAdapter( |
163 |
| - createObjectInstantiator(entity, entity.getInstanceCreatorMetadata())); |
| 163 | + return new EntityInstantiatorAdapter(createObjectInstantiator(entity, entity.getInstanceCreatorMetadata())); |
164 | 164 | }
|
165 | 165 |
|
166 | 166 | /**
|
@@ -239,7 +239,8 @@ ObjectInstantiator createObjectInstantiator(PersistentEntity<?, ?> entity,
|
239 | 239 | @Nullable InstanceCreatorMetadata<?> constructor) {
|
240 | 240 |
|
241 | 241 | try {
|
242 |
| - return (ObjectInstantiator) this.generator.generateCustomInstantiatorClass(entity, constructor).newInstance(); |
| 242 | + Class<?> instantiatorClass = this.generator.generateCustomInstantiatorClass(entity, constructor); |
| 243 | + return (ObjectInstantiator) BeanUtils.instantiateClass(instantiatorClass); |
243 | 244 | } catch (Exception e) {
|
244 | 245 | throw new RuntimeException(e);
|
245 | 246 | }
|
@@ -482,8 +483,7 @@ private void visitCreateMethod(ClassWriter cw, PersistentEntity<?, ?> entity,
|
482 | 483 | String entityTypeResourcePath = Type.getInternalName(entity.getType());
|
483 | 484 |
|
484 | 485 | MethodVisitor mv = cw.visitMethod(ACC_PUBLIC + ACC_VARARGS, CREATE_METHOD_NAME,
|
485 |
| - "([" + BytecodeUtil.referenceName(Object.class) + ")" + BytecodeUtil.referenceName(Object.class), |
486 |
| - null, null); |
| 486 | + "([" + BytecodeUtil.referenceName(Object.class) + ")" + BytecodeUtil.referenceName(Object.class), null, null); |
487 | 487 | mv.visitCode();
|
488 | 488 | mv.visitTypeInsn(NEW, entityTypeResourcePath);
|
489 | 489 | mv.visitInsn(DUP);
|
|
0 commit comments