Skip to content

Commit 3058af5

Browse files
Handle autowired fields
Only handle fields with exact concrete type Don't handle autowired constructor arguments
1 parent c0bd1b4 commit 3058af5

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

env-model-generator/src/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import MapTrackingDuplicates from "./mapTrackingDuplicates";
2020
import NameMap from "./nameMap";
2121
import { makeIdentifier, upperInitialChar } from "./utils";
2222

23-
interface BeanProperty {
23+
export interface BeanProperty {
2424
name: string;
2525
value: Value;
2626
}

env-model-generator/src/parseJson.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,20 @@ export function parseBean(id: string): model.Bean {
6161
}
6262

6363
function parseJsonBean(id: string | undefined, namedBean: BeanWithName): model.Bean {
64-
return new model.Bean(undefined, id, namedBean.qualifiedClassName, model.BeanCreationPolicy.Singleton, [], []);
64+
const bean = namedBean.bean;
65+
const properties: model.BeanProperty[] = [];
66+
for (const fieldName in bean.fields) {
67+
if (!bean.fields.hasOwnProperty(fieldName))
68+
continue;
69+
const fieldClass = bean.fields[fieldName].type;
70+
71+
const fieldBeanId = model.Bean.tryGetIdByClass(fieldClass);
72+
if (fieldBeanId === undefined)
73+
throw new ConfigParseError(
74+
`Autowired field '${namedBean.qualifiedClassName}.${fieldName}' depends on a class '${fieldClass}' `
75+
+ `that has ${model.Bean.hasMultipleBeansForClass(fieldClass) ? "multiple" : "no"} implementations`);
76+
properties.push({ name: fieldName, value: new model.BeanRefValue(fieldBeanId) });
77+
}
78+
// TODO: Handle constructor arguments
79+
return new model.Bean(undefined, id, namedBean.qualifiedClassName, model.BeanCreationPolicy.Singleton, [], properties);
6580
}

0 commit comments

Comments
 (0)