Creating a library jar using Spring boot

冷暖自知 提交于 2019-12-03 15:58:17

This project of mine may be of some interest to you. I have used Spring-Boot to make a library to be used in other projects.

The main thing to note here is to have:

@SpringBootApplication(scanBasePackages = {"me.ramswaroop.jbot", "example.jbot"})

in the main class where you start the spring-boot application. See this main class to learn more. But to be honest, using Spring-Boot to make a library to be included in other projects isn't a good choice according to me. If I were to rewrite JBot then I wouldn't have used Spring-Boot this way surely.

Spring-Boot is really good to create a stand-alone application that you can "just run" but to create a library, hmm, not my favorite choice.

Like Morphic said, you need to decide whether you're going to call the library methods natively using Java or whether you're setting up a web service. It sounds like you're building a REST API, in which case I wouldn't bother including it as a library. I would simply run your spring boot application (java -jar myservice.jar, or mvn spring:boot run), then just connect to it using HTTP REST on whatever port Spring Boot opens for your service.

If you do decide to load the Spring Boot app as a library jar then you probably don't need Spring boot at all. All you need is your service methods and Spring config packaged together as a jar, mvn install to your local repo, then just reference your jar in the vaadin project's pom file (all this assuming you're creating it as a maven project).

If your intention was to let Vaadin call the REST API you've created from the browser (as is usually the case with client-side frameworks like AngularJS), then you're misunderstanding Vaadin. A Vaadin application runs server-side.

So what you can do is run two servers, one running the Vaadin application and which calls the second one running your REST API. But if there's no need for this split, you can use the classes that form the REST API as a regular Java API called directly from the Vaadin application code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!