fix: Autowired Java class error
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
ab7ca932a3
commit
2e4fdcb798
@ -62,14 +62,15 @@ export const JSClass = (className: string) => {
|
|||||||
export const Autowired = (className?: any) => {
|
export const Autowired = (className?: any) => {
|
||||||
return function (target: any, propertyKey: string, index?: number) {
|
return function (target: any, propertyKey: string, index?: number) {
|
||||||
let container = getContainer()
|
let container = getContainer()
|
||||||
if (className instanceof Symbol || className instanceof Function) {
|
if (className && (className instanceof Symbol || className instanceof Function)) {
|
||||||
return inject(className)(target, propertyKey, index)
|
return inject(className)(target, propertyKey, index)
|
||||||
}
|
}
|
||||||
let type = Reflect.getMetadata('design:type', target, propertyKey)
|
let type = Reflect.getMetadata('design:type', target, propertyKey)
|
||||||
if (type && type !== Object) {
|
if (type && type !== Object && Java.isJavaObject(type)) {
|
||||||
inject(type)(target, propertyKey, index)
|
inject(type)(target, propertyKey, index)
|
||||||
named(className || propertyKey)(target, propertyKey, index)
|
named(className || propertyKey)(target, propertyKey, index)
|
||||||
} else if (container.isBound(ioc.Autowired)) {
|
} else if (container.isBound(ioc.Autowired)) {
|
||||||
|
console.debug('Autowired', 'ioc.Autowired', 'named', className || propertyKey)
|
||||||
target[propertyKey] = container.getNamed(ioc.Autowired, className || propertyKey)
|
target[propertyKey] = container.getNamed(ioc.Autowired, className || propertyKey)
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`No matching bindings found for target: ${target.constructor.name} type: ${type} named: ${className || propertyKey}`)
|
throw new Error(`No matching bindings found for target: ${target.constructor.name} type: ${type} named: ${className || propertyKey}`)
|
||||||
|
@ -17,6 +17,7 @@ declare global {
|
|||||||
function to<T = any>(array: T[], type?: T): T[]
|
function to<T = any>(array: T[], type?: T): T[]
|
||||||
function extend(...parentTypes: any[]): any
|
function extend(...parentTypes: any[]): any
|
||||||
function synchronized(func: () => void, lock: any): Function
|
function synchronized(func: () => void, lock: any): Function
|
||||||
|
function isJavaObject(obj: any): boolean
|
||||||
function asJSONCompatible<T = any>(obj: T): T
|
function asJSONCompatible<T = any>(obj: T): T
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
// function super(type: any);
|
// function super(type: any);
|
||||||
|
Loading…
Reference in New Issue
Block a user