[英]How to add a Spring Boot support to an external library?
I have a library I'm developing, and let's say it offers some service FooService
.我有一个正在开发的库,假设它提供了一些服务
FooService
。
Now, in order to instantiate it you need to pass some arguments to the constructor.现在,为了实例化它,您需要将一些参数传递给构造函数。
Typically (if FooService
is in the same project), you are supposed to write FooServiceConfig
class annotated with @Configuration
and instantiate using @Value
ed properties.通常(如果
FooService
在同一个项目中),您应该编写带有@Configuration
注释的FooServiceConfig
类并使用@Value
ed 属性进行实例化。
How can it be done when you use FooService
from an external library?当您从外部库使用
FooService
时如何完成?
What I'd like to achieve is to be able to instantiate the FooService
using @Autowired
(and putting the correct config in application.properties
)我想要实现的是能够使用
@Autowired
实例化FooService
(并将正确的配置放入application.properties
)
If your library is supposed to work within Spring's projects you can create your own auto-configuration .如果您的库应该在 Spring 的项目中工作,您可以创建自己的自动配置。
Once you have everything configured it will work in the same way as any other spring-boot-starter.一旦你配置好了所有东西,它就会像任何其他 spring-boot-starter 一样工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.