Combine frontend Thymeleaf with backend Spring Boot - spring-boot

How to call the backend API from front end which is thymleaf based when both the frontend and backend API are 2 different microservices.
And also I have a Eureka Server and microservices that are registered to this server. I have the frontend and backend APIs ready.
Can anyone help in how can I make the API call to the other microservice from the Thymeleaf templates html.
Following is the Architecture for my microservice:-
Application Architecture
Using Thymeleaf as frontend template.
Created the following modules:-
web-ui module : Thymeleaf
service-registry : Eureka Server
search-service & product-service : Spring Boot and
EurekaDiscoveryClient
Need help in communication of web-ui with service-registry but not sure how to implement the api-gateway.

Related

Load a index.html dependent of domain in Spring Boot

I have a Spring Boot project as backend and an Angular project for the frontend.
For now, I use spring to service angular from the static resources, but coming soon I will need to load different angular projects depending on the domain used to access to service.
I can load different static resources by default depending on the domain in Spring Boot?
Example:
resources.add("domain1.com", "resources/static/domain1/");
resources.add("domain2.com", "resources/static/domain2/");

Difference between spring-boot-admin server and client

There are no much resources on this topic so thought to post it. Also I myself am trying to understand the different. Previously we just had only spring-boot application. So can anybody explain the difference.
Spring boot admin is nice monitoring dashboard for spring boot application. To feed data to this dashboard spring boot admin provide two approaches:
1) Using client library: client libary will send data to spring boot admin dashboard.
2) Use service discovery (eureka)

Registering Spring Cloud Microservice with Eureka server

I am trying to create spring cloud microservices and also need to include eureka server and zuul as spring cloud tools. Now I created one module in my one spring boot project. I registered that service with eureka server. And also I created one spring boot project for adding zuul service discovery and also registered with eureka project.
Here my doubt is that When I am adding another module as another spring boot project, Can I register that application also with my current eureka server as client? What type of relation that eureka server project and microservice having? one-To-One or One-To-Many? Can I register 3 or 4 microservices with one eureka server as client?
Eureka Server will let you add as many microservices (modules of spring boot projects like you said).
From Spring Cloud landing page:
As long as Spring Cloud Netflix and Eureka Core are on the classpath
any Spring Boot application with #EnableEurekaClient will try to
contact a Eureka server on http://localhost:8761 (the default value of
eureka.client.serviceUrl.defaultZone):
That means that you can use a single eureka server for multiple microservices which are registered as clients to the eureka server.
So yes, it's a One-To-Many relationship.
You will want at one point to look into multiple Eureka servers used in load balancing, for redundancy purposes, but for now you will be fine.

Angular 2, Spring boot , spring security , login form

I have a Front end application that runs on http:// localhost:4200, with angular 2 (I've used angular-cli for generating the project).
The application runs without any problems (I can get and post info from/to database using Angular 2 Http service:
getList () {
return this._http.get("http:// localhost:8080/").map(res => res.json());
}
On the other hand, I have a Back end application running with spring boot on http:// localhost:8080/ (note the ports), that provide a REST Api for my angular 2 application.
Sending requests from http://localhost:4200/ to http://localhost:8080/ works as expected.
Before I've programmed an application with spring framework & angularJS 1, spring security took care of login and security in the same app (maven project).
Now I have two separate applications that are communicating via http (RESTful Api with spring boot , and front end Api with angular 2)
How can I set my login form and where to put it, and how to configure spring security with my angular 2 application?
When you spin up the Angular Application with Angular CLI, your Angular Pages are served by NodeJs in the backend.
You have a couple of options here.
The login can be handled at NodeJS server which can in turn invoke
Spring Boot application to Authenticate and Authorize.(I think, you might need to do some tweaks like using express server instead of lite server. take a look here https://stackoverflow.com/a/37561973/6785908)
After initial development, you can copy over your AngularJS
resources to a Spring MVC (Spring Boot) server and use it to serve
your pages (as well as the rest APIs), just as you were doing
before.
Make the Angular App invoke the spring boot Service (I guess , you
are using the $http.post to submit the form, if that's the case you
can just change the URL so that it can hit spring boot app instead.)
For the production deployment, use nginx/httpd to serve the static
files (AngularJS/CSS etc) and route/proxy all the dynamic request to
the spring boot app.
I would strongly suggest the 3rd option.

Spring service and Spring web app in one

I'm making a Spring RESTFUL service and i wonder. Can I make a Spring RESTFUL service combine with a web app in a project. If it is possible, how to configure it?
.
yes that is possible to combine with web-app
for example your controller package into your restful controller also work
that is possible to crud operation via restful web service.

Resources