From c7079dd82e743684fbad9d502cdce43a528cde87 Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Fri, 2 Oct 2020 18:48:37 +0800 Subject: [PATCH] fix: Autowired Java class error Signed-off-by: MiaoWoo --- packages/container/src/index.ts | 5 +++-- packages/nashorn/src/index.ts | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/container/src/index.ts b/packages/container/src/index.ts index f3d99391..ea96dd81 100644 --- a/packages/container/src/index.ts +++ b/packages/container/src/index.ts @@ -62,14 +62,15 @@ export const JSClass = (className: string) => { export const Autowired = (className?: any) => { return function (target: any, propertyKey: string, index?: number) { let container = getContainer() - if (className instanceof Symbol || className instanceof Function) { + if (className && (className instanceof Symbol || className instanceof Function)) { return inject(className)(target, propertyKey, index) } let type = Reflect.getMetadata('design:type', target, propertyKey) - if (type && type !== Object) { + if (type && type !== Object && Java.isJavaObject(type)) { inject(type)(target, propertyKey, index) named(className || propertyKey)(target, propertyKey, index) } else if (container.isBound(ioc.Autowired)) { + console.debug('Autowired', 'ioc.Autowired', 'named', className || propertyKey) target[propertyKey] = container.getNamed(ioc.Autowired, className || propertyKey) } else { throw new Error(`No matching bindings found for target: ${target.constructor.name} type: ${type} named: ${className || propertyKey}`) diff --git a/packages/nashorn/src/index.ts b/packages/nashorn/src/index.ts index 0a550f53..cb5d4692 100644 --- a/packages/nashorn/src/index.ts +++ b/packages/nashorn/src/index.ts @@ -17,6 +17,7 @@ declare global { function to(array: T[], type?: T): T[] function extend(...parentTypes: any[]): any function synchronized(func: () => void, lock: any): Function + function isJavaObject(obj: any): boolean function asJSONCompatible(obj: T): T //@ts-ignore // function super(type: any);