Consolidate spring boot micro services under swagger - spring-boot

I have started creating a project using springboot. There are multiple micro modules each having different controller. How can I expose all the controllers on a single host,port combinations. Also How can I make swagger to list all apis across different controllers.
The project is like
ABCD\
--\A\A Controller
--\A\build.gradle
--\B\B Controller
--\B\build.gradle
--build.gradle
Thanks for any pointers.
Is there a way I can make a collective war having all the controllers inside it
I am using springfox.io for the same. The challenge is I can get all the api listed in springfox/swagger provided if I jar all the modules and add to the modules with springfox config. But for this I have to create separate module and everything is running on one server. I want A controller to be running in one tomcat and B in another, and springfox on either C or any of A or B, but listing all apis of A and B. There might me some use case I am missing, please let me know.

Related

How to generate swagger code gen for a spring boot project

I need help in getting clarification for below mentioned points
I have a swagger json. From this I want to generate Model separately by passing java as language. api and invoker clsses by passing spring as language and want to add model jar as dependency. Because I want to use model for different projects commonly. So I want to include a build task to generate model jar every time to get latest models from json. and will issue swagger code gen command with spring as language while trying to create project. Is this correct way of handling. If not can someone let me know best of handling this.
How to handle versioning from swagger.
I am new in using swagger and spring. Please suggest me best to go
I do something similar. I have my models in a separate project which is then a dependency for a bunch of API projects. This is because the APIs sometimes call each other, so need to know about each others objects.
What I do is:
Swagger structure:
In the models project I have a swagger containing just the definitions (empty object as paths)
In the API projects I have a swagger which references the definitions in the models project
Build process
Build the models project first with generateApis = false
Build the APIs with typeMappings and ImportMappings in the config, telling them to take all the models in common from that namespace
I use the maven plugin to run the codegen. I have a pretty hacky bash script that updates the type mappings in the pom when I have added new objects to the models

Using microservices architecture in spring

I'm building a project which based on microservices architecture in spring boot.The project was divided multiple modules and I used maven dependency management.
Now I want to use services from one module in other module. I have many spring applications. For example, I have 2 application which is named A and B. I want to use classes from A in B and classes of B in A. In this case I used maven dependencies but it is not completely way to using services in one another because I faced with circular dependency.
What should do to use for solve this problem?
It is not a good idea to share classes between microservices, if you want to replace microservice A, you'll have to adapt Microservice B.
Every Service must implement its own data classes which holds the fields which are needed for the service.
MicroService A and MicroService B both can contain a class Foo but this classes can be different by its fields. Perhaps both contain the field 'id' and 'name' but only Microservice A also needs a field 'date' to do his work.
If you have classes that need to be in some of your Microservices, i think it's better to make a shared library and put your shared classes in that, then use your shared library in your Microservices.
Actually i think it's a good idea to put classes that need to be in most of your Microservices in a shared library and use that library. But should be careful, because it may comes to tight coupling which isn't a good thing in Microservices Architecture.
Personally i think some Configuration classes and some Event models that most of your Microservices use are good candidates. But i don't think sharing your Service classes between your Microservices are a good idea. Instead they should use each other's services as they are completely independent and are using external services.
create one common entity application and add that entity application as a dependency. For example assume you have stored user data in micorservice1(MC1) and need this class(User) in other microservices(like MC2, MC3,MC4, and so on) then you can create one entity application like util and add this dependency in required microservices.

Microservice project structure using Spring boot and Spring Cloud

I am trying to convert a normal monolithic web application into microservices structure using Spring Boot and Spring Cloud. I am actually trying to create Angular 2 front-end application and calls these my developed microservices in the cloud. And I am already started to break the modules into independent process's structure for microservice architecture.
Here my doubt is that, when designing the flow of control and microservice structure architecture, can I use only one single Spring Boot project using different controller for this entire web application back end process?
Somewhere I found that when I am reading develop all microservices using 2 different Spring Boot project. I am new to Spring and Spring Cloud. Is it possible to create all services in single project by using different modules?
Actually, it doesn't matter to package all those services into ONE project. But in micro-service's opinion, you should separate them into many independent projects. There are several questions you can ask yourself before transforming original architecture.
Is your application critical? Can user be tolerant of downtime while you must re-deploying whole package for updating only one service?
If there is no any dependency between services, why you want to put them together? Isn't it hard to develop or maintain?
Is the usage rate of each service the same? Maybe you can isolate those services and deploy them which are often to be invoked to a strong server.
Try to read this article Adopting Microservices at Netflix: Lessons for Architectural Design to understand the best practices for designing a microservices architecture. And for developing with Spring Cloud, you can also read this post Spring Cloud Netflix to know which components you should use in your architecture.
Currently I am working on microservices too, according my experience we have designed microservices as step below,
Maven
You should create the project with different project. But actually you can separate your project to submodule. So you will be easy to manage your project, the submodule you can use with other project too.
Build the Jar Library put your local repository. it can save your time, you have just find the same component or your functionality then build the jar file put in your local repository , so every project that use this function call point to download this repository, you don't have to write many project same same.
So finally I would like you to create different springboot project, but just create submodule and build local repository.
By creating your modules in different projects you create a more flexible solution.
You could even use different languages and technologies in a service in particular. E.g. one of your services could be NodeJS and the rest Java/Spring.

differentiate between maven multi module and Spring micro services?

I am reading spring micro services for next project. Tut said that "The architecture style the main application divided in a set of sub applications called microservices. One large Application divided into multiple collaborating processes.". So already we have a framework maven multi module There I separated the project in my experience. even though it is. why do we need micro services to separate a project?. please differentiate it. thanks in advance..
Every service in the microservice architecture should be isolated which means that the team in charge of that service is able to put continuous deployment in practice without need to deploy other services. In practice, IMHO I think that we can use two approaches using our favourite build tool such as maven or gradle:
Monoproject: domain, repositories, services and controllers are all in the same project.
Multiproject: domain, repositories, services and controllers can be grouped in different modules. i.e domain and repositories are in repository module and services in another module with the same name and controllers in front module.
But, doesn't matter which approach you use the project (mono or multi) should represent one service.

Grails + Idea module project

I want to spread my grails application into several modules.
For example,
i want to cteate one CoreModule it will has domain classes and
base services.
Then AdminPanelModule and RestServiceModule.
They will has own controllers and own specific services. But they
have to get access to CoreModule's domain classes and services.
Than I want to deploy 2 CoreModule apps, and 1 AdminPanelModule app on different hosts. Help me plz.
How can I organize dependencies with Idea?
What i need to do, to create correct run configuration?

Resources