简体   繁体   English

普通Java项目中的Spring Boot库用法

[英]Spring Boot library usage in plain Java project

i´m currently working on a Spring Boot jar library for reuseable components like 我正在开发一个Spring Boot jar库,用于可重用的组件

  • ldap LDAP
  • email 电子邮件
  • messaging with apache kafka 用apache kafka发送消息
  • rest api usage 休息api用法

Aim: 目标:
Every Java "user/coder" of our company should be able to "put" this jar in ones project (by maven or whatever) and use the reusable components instead of coding all things by hand over and over again. 我们公司的每个Java“用户/编码器”都应该能够将这个jar“放”到一个项目中(通过maven或其他)并使用可重用的组件而不是一遍又一遍地编写所有东西。

Building microservices for that issue over REST is not an alternative to us. 通过REST构建针对该问题的微服务不是我们的替代方案。

My question is: 我的问题是:
Can i reuse this Spring Boot jar library in any plain Java projects? 我可以在任何普通的Java项目中重用这个Spring Boot jar库吗?

Beeing fond, can i "put" this jar library into a Java project and wire my Spring Boot services from that library in my "non Spring Boot" vanilla Java project? Beeing喜欢,我可以将这个jar库“放”到Java项目中,并在我的“非Spring Boot”vanilla Java项目中从该库连接我的Spring Boot服务吗?

Notice / Edited: 通知/编辑:
I have used Spring Boot as project template ( spring-boot-starter-parent ). 我使用Spring Boot作为项目模板( spring-boot-starter-parent )。
I configure my templates like the LdapTemplate by hand and don´t let Spring Boot do the magic. 我手动配置我的模板,如LdapTemplate ,不要让Spring Boot发挥魔力。

Edit 编辑
As far as the reuse in Spring Boot/Spring projects is concerned, everything is fine. 就Spring Boot / Spring项目的重用而言,一切都很好。 I´ve done that already. 我已经这样做了。

My aim with that library may be that every Java "user" can use this library, like so: 我对该库的目标可能是每个Java“用户”都可以使用这个库,如下所示:
final SuperCoolLibary scl = new SuperCoolLibrary(); final boolean exists = scl.searchForLdapUser("tlang");

So another question maybe: 另外一个问题可能是:
Would it be better do switch this library to maybe the new Java Jigsaw module infrastructure? 将此库切换到新的Java Jigsaw模块基础结构会更好吗?

  1. Write your own Spring-Boot-Auto-Starter. 编写自己的Spring-Boot-Auto-Starter。 A guide can be found under: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-auto-configuration.html 可以在以下网址找到指南: https//docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-auto-configuration.html
  2. This way your library can be used in every spring boot project by just adding it as dependency (which means the jar must be in your classpath). 这样,您的库可以在每个Spring启动项目中使用,只需将其添加为依赖项(这意味着jar必须位于类路径中)。
  3. If your Java Application does not use the SpringContext the services cannot be "wired" by spring into your plain vanilla java application. 如果您的Java应用程序不使用SpringContext,那么服务就无法通过Spring连接到普通的java应用程序。

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

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