简体   繁体   English

无法将自定义 spring 引导库项目自动连接到我的应用程序

[英]unable to autowire custom spring boot library project to my application

Importing custom spring-boot library jar to my application, and autowiring show the following error when I run the application将自定义 spring-boot 库 jar 导入我的应用程序,并在我运行应用程序时自动装配显示以下错误

Parameter 0 of constructor in com.dilla.de.orca.addresssvc.service.TestScheduler required a bean of type 'com.dilla.de.orca.flowersvc.service.FlowerServiceImpl' that could not be found.

The Library module has following packages图书馆模块有以下包

  • Configuration配置
    • FlowerServiceConfiguration - create beans for Jaxb2Marshaller, WebServiceTemplate, webserviceMessageSender FlowerServiceConfiguration - 为 Jaxb2Marshaller、WebServiceTemplate、webserviceMessageSender 创建 bean
  • Model Model
  • Service服务
    • FlowerService (an interface no annotation) FlowerService(一个没有注解的接口)
    • FlowerServiceImp implements the interface and calls FlowerAdapter FlowerServiceImp 实现接口并调用 FlowerAdapter
    • FlowerAdapter (call external webservice) FlowerAdapter(调用外部网络服务)
  • Src/main/resources源/主/资源
    • Application.properties define external webservice url, and related properties Application.properties 定义外部 web 服务 url 和相关属性
FlowerSvcLibApplication.java
    public static void main(final String[] args) {
        SpringApplication.run(FlowerSvcLibApplication.class, args);
    }

I was autowiring the Flower Service interface as follows, in my application to test functionality of library jar我在我的应用程序中自动装配 Flower Service 接口,以测试库 jar 的功能

@Component
public class MyFlowerService {

    private  FlowerService service;
    @Autowired
    public MyFlowerService(final FlowerService service) {
        this.service = service;
    }

I got the error I posted earlier.我收到了我之前发布的错误。 I did do more research, and one suggestion was creating “own auto-configuration”, but I still did not understand.我做了更多的研究,一个建议是创建“自己的自动配置”,但我还是不明白。 How do I create autoConfiguration class to handle to autowire my library class, and also how does client using my library provide application property values.如何创建自动配置 class 来处理自动装配我的库 class,以及使用我的库的客户端如何提供应用程序属性值。 Currently, I hard coded actual values for example a webservice url, and now client can change this to be test or prod, and to do that how does my library module setup should be?目前,我对实际值进行了硬编码,例如 Web 服务 url,现在客户端可以将其更改为测试或产品,为此我的库模块设置应该如何?

Please check @ComponenetScan & make sure that it has package path something like this “com.dilla.de.orca”请检查@ComponenetScan 并确保它具有类似“com.dilla.de.orca”的 package 路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM