Creating a library jar using Spring boot

前端 未结 3 1623
眼角桃花
眼角桃花 2021-02-06 12:27

I created a spring boot application having REST web services and jpa dependencies. The application runs on its own as a standalone application. I\'m trying to add UI layer usin

相关标签:
3条回答
  • 2021-02-06 12:39

    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.

    0 讨论(0)
  • 2021-02-06 12:57

    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 sure. I think a library should have fewer dependencies as possible.

    0 讨论(0)
  • 2021-02-06 13:00

    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).

    0 讨论(0)
提交回复
热议问题