Create a web application using Spring framework for back-end but without using Spring MVC.s - spring

I want to learn the Spring Framework and therefore I decided to make a web application using it, but I don't want to use Spring MVC as it still uses JSP. What all projects from Spring can be used if I want to have a UI which can be made using React / Angular and the backend is managed by Spring.

You have to use REST API, and pass data to front-end JS framework via JSON.
Look here: https://spring.io/guides/gs/rest-service/
Start with creating a simple Rest Controller with Spring Boot.
Then you have to choose your JavaScript framework (jQuery, Angular, React),
and make a HTTP request to URL typed in your #RestController.
You can achieve this by using AJAX method from your JS framework.

Try this,it will speed up your development
Restful Web Service with Spring Boot
by the way,if you want to use Angular/React+Spring Boot you can use JHipster, this tool will just do the basic setup for your Angular/React+Spring Boot application in couple of minutes,the website has a clear video tutorial you can use it will only take about 15 min approx
Jhipster

Related

How to call Rest request from jsp

I have to create 2 projects. Web Service and one is Web project.
I created the web service using Rest in spring boot and web project using dynamic web project using Jsp and servlets.
Now I have to consume the web service in web project. How can I do ?
You can do AJAX call from your JSP side to your REST server side using Javascript. You can also use library like JQuery or axios (there MDN versions since you are using JSP) to send REST API calls to your same or any other server. You can follow https://stackoverflow.com/a/44859872/8684299 this answer.

How to connect Java spring application with Angular 4 application

I made a Spring rest application and Angular 4 application and I want to use Spring rest Api's in my Angular 4 application. Simple CRUD application. which could be the best format of communication between these application
You can take a look at this Spring Guide.
It is for AngularJS, but the server side code is absolutely the same in case of Angular 2,3,4 as well.
If possible try not to club angular and spring-boot together, sure you can do this using webjars or similar libraries, but try not doing it. Spin off the angular app as a separate application (you can serve this Angular app either using nginx or nodeJs) and then route all the API calls through the Angular App to your Spring boot application. Now your spring boot application will be just a ( micro ) service which will have to deal only with the data, not the presentation (markup / style etc).

How enable Angular Universal with a Java/Spring backend?

I have an app, where backend implements on Spring using Spring Boot and front-end side use Angular2. Can somebody help me and explain how to integrate Universal using Java becken. Or show me a good example how I can do that.
how to integrate Universal using Java beckend?
You cannot do that directly as universal needs a different server side technology -nodejs
But you have a another (better) solution
Spin off a separate nodejs app for the angular and universal then route all the API calls through the nodeJs to your Spring boot application. Now your spring boot application will be just a (micro)service which will only deal with the data, not the presentation (markup/style etc)

Plain Servlet vs Spring MVC

I have to create a web application, I need to use my back-end code for mobile apps also.
I know Servlet, I thought of doing this application with "REST API" + HIBERNATE for server side and Javascript(Angular JS ) in UI.
Some of my colleagues suggest to do this with Spring. I don't know anything about Spring. While reading about Spring I came to know that back-end logic and UI code can be in same place. It seems it is tightly coupled with back-end and front-end.
Some times back Jquery is more preferable JS framework but now everyone suggests Angular JS. This will be changed after some times. But logic I am going to write in back-end will be the same.
How can I choose the correct one?
I suggest to use:
Spring web MVC for backend https://spring.io/guides/gs/serving-web-content/, maybe with Spring Boot, and Hibernate for DAO layer. Here you can find a helpful example (without Spring Boot): http://websystique.com/springmvc/spring-mvc-4-and-spring-security-4-integration-example/
and for frontend certainly Angular 2, with TypeScript, instead of Angular js, and here reach the REST service exposed by backend.
These days it is easy to build a REST based back end with no libraries at all if you deploy to a Java EE 6/7 server such as WildFly, TomEE or Payara (amongst others).
You get JAX-RS and JSON-P (for rest), JPA for persistence, web sockets, asynchronous processing, transaction management and the rest of the Java EE stack for free.
Try a google search for Java EE thin war - there's lots of examples about

Spring REST API for web- and mobile-clients

This is my first question on StackOverflow and I hope someone can help me. :-)
I am planning to build a web-application (backend) with spring roo. For the backend I will use Spring and Hibernate/JPA. In the future I will implement a web client (JSF/Primefaces), a mobile client (Android) and a Windows App.
With spring roo it is easy to create a layered architecture with domain classes, repositories and services. This part is fun.
But now I am thinking about remoting and how to connect all the clients (web, mobile, windows) with my backend.
1.) What do you prefer for the remoting between client and backend? SOAP-Web Services or a REST-API (e.g. with JSON).
2.) If REST-API: How should the API look like for authentication/login functionality? REST is resource-oriented but how do you implement authentication with REST API?
At the moment I think a REST-API is a good idea. Because I am using spring it is easy to create a Spring MVC controller with REST support. But is this the correct way to implement a REST API for all the three devices? The web client e.g. should be implemented with JSF and Primefaces and I donĀ“t use spring MVC for the web layer.
3.)Can I nevertheless use Spring MVC controllers to build the REST API (together with JSF in the web layer)? Or is there a better way?
1.) What do you prefer for the remoting between client and backend? SOAP-Web Services or a REST-API (e.g. with JSON).
I don't have too much experience with SOAP-WS, but I have a ton of experience with REST-APIs using JSON. There are many implementations for mobile, web and server side clients that are fairly simple to implement.
2.) If REST-API: How should the API look like for authentication/login functionality? REST is resource oriented but how to implement authentication with REST API?
If you are already using spring, I recommend securing your API with Spring Security. You can use spring security even if you don't end up going with Spring MVC for your API implementation. There are many ways to secure a rest API with spring security, but I the simplest is to send the basic auth header with every request to a secure URI
3.)Can I nevertheless use Spring MVC controllers to build the REST API (together with JSF in the web layer)? Or is there a better way?
Spring MVC Controllers will work fine, but I would recommend going with RestEasy or Jersey. I find them to be more flexable.
I agree with #mad_fox. Additionally, i want to add another option regarding your question#2. If you dont want to use Spring security, you can write your own token based authentication mechanism using spring and basic java interceptors.
You can store the token in your browser local storage.

Resources