运行 拥有 spring 没有主库的库 class

Run own spring library without main class

我已经创建了一个 spring 其他应用程序可以使用的库 use.Below 是我可以在其他应用程序中作为 maven 依赖项使用的工作代码。 我的问题是我如何 运行 没有客户端的库,因为库没有 main 方法。

    @Component
    public class MyService {
        
        
        public String logError(String s ) {
        return "Hello World";
        }
        }

@Configuration
@ComponentScan("com.custom.lib.config.MyLibConfig")
@EnableJpaRepositories("com.custom.lib.config.MyLibConfig")
@EntityScan("com.custom.lib.config.MyLibConfig")
public class MyLibConfig {
    
}

我在库代码中有 META-INF 文件夹

org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.custom.lib.config.MyLibConfig

您可以编写 spring.factories 文件,您可以 运行 从文件中提取库。当 spring 扫描库时,它会自动 运行 类 在 META-INF/spring.factories 文件中定义。您可以在 google 中轻松搜索关于 spring.factories 的内容。当然你已经添加依赖到你的mvn或者gradle文件