node-web-mvc
Version:
node spring mvc
45 lines (44 loc) • 2.11 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @module AutowiredBeanProcessor
* @description 自动装配处理
*/
const BeanPropertyCreationException_1 = __importDefault(require("../../errors/BeanPropertyCreationException"));
const ElementType_1 = __importDefault(require("../../servlets/annotations/annotation/ElementType"));
const RuntimeAnnotation_1 = __importDefault(require("../../servlets/annotations/annotation/RuntimeAnnotation"));
const Autowired_1 = __importDefault(require("../annotations/Autowired"));
const AutowiredUtils_1 = require("./AutowiredUtils");
const InstantiationAwareBeanPostProcessor_1 = __importDefault(require("./InstantiationAwareBeanPostProcessor"));
class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBeanPostProcessor_1.default {
constructor(beanFactory) {
super();
this.beanFactory = beanFactory;
}
postProcessProperties(pvs, beanInstance, beanName, definition) {
const clazz = beanInstance.constructor;
const annotations = RuntimeAnnotation_1.default.getAnnotations(Autowired_1.default, clazz);
for (const annotation of annotations) {
if (annotation.elementType !== ElementType_1.default.PROPERTY) {
continue;
}
const proprty = annotation.name;
const componentAnno = annotation.nativeAnnotation;
const optional = componentAnno.required === false;
const clazzType = (0, AutowiredUtils_1.getBeanTypeByAnnotation)(annotation);
if (!clazzType) {
throw new BeanPropertyCreationException_1.default(definition, beanName, proprty, `beanName is null`);
}
pvs.push({
optional,
name: proprty,
value: this.beanFactory.getBean(clazzType),
});
}
return pvs;
}
}
exports.default = AutowiredAnnotationBeanPostProcessor;