Spring Boot library usage in plain Java project

时间:2019-04-08 12:52:50

标签: java spring spring-boot

i´m currently working on a Spring Boot jar library for reuseable components like

  • ldap
  • email
  • messaging with apache kafka
  • rest api usage

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.

Building microservices for that issue over REST is not an alternative to us.

My question is:
Can i reuse this Spring Boot jar library in any plain Java projects?

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?

Notice / Edited:
I have used Spring Boot as project template (spring-boot-starter-parent).
I configure my templates like the LdapTemplate by hand and don´t let Spring Boot do the magic.

Edit
As far as the reuse in Spring Boot/Spring projects is concerned, everything is fine. I´ve done that already.

My aim with that library may be that every Java "user" can use this library, like so:
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?

1 个答案:

答案 0 :(得分:4)

  1. Write your own 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
  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).
  3. If your Java Application does not use the SpringContext the services cannot be "wired" by spring into your plain vanilla java application.