从依赖库jar自动装配Bean

时间:2019-10-15 16:40:59

标签: spring-boot dependency-injection

我有一个let json = [ { "metadata": { "id": "vvvvvvvvvvvvv", "url": "cccccccccccccc", "created_at": "2019-09-06T08:40:41Z", "updated_at": "2019-09-06T13:25:46Z" }, "entity": { "name": "app1", "b_enabled": false, "d_url": "xxxxxs" } }, { "metadata": { "id": "vvvvvvvvvvccc", "url": "cccccccccccccc", "created_at": "2019-09-06T08:40:41Z", "updated_at": "2019-09-06T13:25:46Z" }, "entity": { "name": "app2", "b_enabled": false, "d_url": "xxxxxs" } }, { "metadata": { "id": "vvvvvvvvvvddd", "url": "cccccccccccccc", "created_at": "2019-09-06T08:40:41Z", "updated_at": "2019-09-06T13:25:46Z" }, "entity": { "name": "app3", "b_enabled": false, "d_url": "xxxxxs" } }, { "metadata": { "id": "vvvvvvvvvveee", "url": "cccccccccccccc", "created_at": "2019-09-06T08:40:41Z", "updated_at": "2019-09-06T13:25:46Z" }, "entity": { "name": "app4", "b_enabled": false, "d_url": "xxxxxs" } }, { "metadata": { "id": "vvvvvvvvvvfff", "url": "cccccccccccccc", "created_at": "2019-09-06T08:40:41Z", "updated_at": "2019-09-06T13:25:46Z" }, "entity": { "name": "app5", "b_enabled": false, "d_url": "xxxxxs" } } ] let output = {}; // we parse each element of the json array for(let i = 0; i < json.length; i ++ ) { // we get the current element. let currentElement = json[i]; // here, we are using the name of the entity as the key and the id of the metadata as the value output[currentElement.entity.name] = currentElement.metadata.id; } console.log(output);Spring Boot application),该用户使用的是jar jar main-app,并提到它是应用程序client-app.jar的依赖项。

现在,我想使用main-app@Autowire注入bean。为此,我必须在我的client-app应用程序上添加@ComponentScan

但是有一种方法可以通过更改main-app上的代码来使main-app上的任何内容都不需要。

1 个答案:

答案 0 :(得分:0)

是的,您可以按照sub-package来创建main-app,假设main-app具有包com.example.main-app的以下根,然后在您的client-app上,创建类似com.example.main-app.client-app之类的内容,然后主应用程序将扫描其基本程序包,并且外观也将为client-app