I am considering moving from server-side rendering view technologies like JSP, Struts to client-side rendering view technologies using AngularJS,
A popular Javascript framework for modern browsers.
When we are making this change and what are all the things that I may encounter.
If anybody who are experienced in Spring Web MVC and JSP development and would know how Spring MVC can work together with a client-side Javascript like AngularJS.
Kindly Answer.
You have to rewrite the view part using angularJS, and replace the logic from the server with a REST API.
It's often a huge work, and the hardest part is to migrate the existing server-side session management to the browser, because a REST API is stateless.
Below is one of the suggested way in which i recently migrated my existing spring MVC web-application in Single page application using AngularJs as client side java-script framework:
1).First you needs to bisect your core business logic which must needs to handle in DB layer,if not done already. i.e. SP's,trigger's,etc...
2).Then for the thing mentioned as hardest by Toilal ("to migrate the existing server-side session management to the browser, because a REST API is stateless"), you can consider Spring Boot as one of the options to build things quickly instead of Spring MVC with fusion of java8 features to yield the JSON response via API's.
3).And than last but not the least, build UI layer with AngularJS in front End encapsulating the data returned by the spring boot API's. Please note that as angular is super power full, you can do most of your business logic at client side,your DB layer just needs to give you the whole bunch of business data to render the screen,other things you can easily handle in angular.
Thus, this way by making the DB layer thin and imbibing angular at front end, you can improve performance of your existing application drastically.
You can also check this AngularJS with Spring-mvc useful thread in same context.
Related
I'm new at Spring MVC framework i want to learn how to fully separate frontend(html,js etc.) and backend(java).
I'm going to use RESTfull services, play with JSONs.
I think i'm going to build Single Page Application.
Most of tutorials shown in jsp pages which i dont like.
I saw my friends company project(Using Spring MVC) they used Embedded Jetty server and in server configuration they assigned two different paths for frontend and backend paths.
I saw frontend codes there was only html javascripts etc. on the backend side the approach was the same.(Fully Separated !!!)
My question is:'How they pass requests from frontend to backend and get results from backend and update frontend'.
Also they were using Maven backend and frontend defined as modules in the root.
Could you share tutorials so i can understand playing with codes ?
'How they pass requests from frontend to backend and get results from
backend and update frontend'
They probably use HTTP[S] as the transport and JSON as the data representation format. Browsers support AJAX which allows you to make HTTP connections without reloading the page.
Could you share tutorials so i can understand playing with codes ?
No, that's not what this site is for.
Comments:
JSP is still very useful for generating HTML on the server. This is pretty close to necessary if you want Google to crawl your site.
Check out Spring Data REST for a framework for quick REST APIs.
Also check out ExtJS or Dojo for good Single Page App frameworks.
I am planning to start a project and I am looking for the best approach to make a RIA application using AngularJS.
Right know I am pretty sure of those technologies:
AngularJS (+ bootstrap CSS) for the client UI, logic and server
requests.
Spring for bootstrapping the server business logic.
Hibernate + MySQL for persistent data access
Jersey for the Restful web service API.
Spring Security for url and data protection over authentication.
The only piece I feel is not ok is that my application will not be the typical one page app, because it will be large and I want to break it into multiple one page apps, some protected and others public. To serve every index.html I want another technology like Spring MVC, making those small one page apps secure for this points, and also not allowing the access to some resources.
¿Do you think this is a good approach or you would change any of this technologies (like supressing jersey/Spring MVC redundant dependencies)?
i think that in general your aprroach is a good one, but maybe you could use the webapp generator yeoman with the JHispster, a java web app generator.
Or if you don't like the ideia you could add to your data access layer the Spring-Data-JPA, because you will avoid to write the boilerplate code.
We are developing an Enterprise application with the following technology stack:
Websphere Application Server
Spring (Webflow (Session in View pattern), JPA (Hibernate), Core)
DB2 osZ
Frontend (JSP Rendering HTML5 (CSS 2.0), Ajax in combination with webflow, JQuery)
Multiple Single Pages design combined by using webflow for supporting
subflows
Development Methodology
- Domain Driven/Component Driven Application
- Test Driven Development
Current Situation
Our domain model has very deep domain class hierarchy and therefore we decided to use webflow to allow deep class navigation in sub flows.
We are using the “session in view pattern” because there are many screens reflecting the class hierarchy of the domain model.
This worked very well because of having the backend managing session scoped data for the frontend.
What do we want to do next?
Single Page Design
Control User data in session
Control User data across screens
Support multiple instance of a browser in one user session
Want to be able to talk to the backend (Enterprise Java/Spring) to
retrieve data and persist
Support more state-of-art user experience
Technology Stack
Websphere Application Server
Spring (Webflow (Session in View pattern), JPA (Hibernate), Core)
DB2 osZ
Frontend (Angular, JQuery, Bootstrap 3)
So the discussion internally is how to integrate Angular?
Should we give up Webflow and solve everything with Angular?
Does a mix make sense?
We have taken the following chart as a reference:
http://vschart.com/compare/angularjs/vs/spring-framework
We know what both frameworks are able to do, and know how to make them work. We are interested in other teams experience on how to integrate Angular? Did someone ever mix Webflow and Angular?
We are interested to see some best practices and how teams have transitioned to either framework or keeping both?
Thanks for input,
Andrew
I suggest you to check the Java library thymeleaf in order to get directly the benefits of HTML5 which you can easily add AngularJS and build on top of it (with bootstrap if you need it), and use Spring Security for Auth & session management.
As loose coupling at all levels (front-end included) is most of the times desirable, try to avoid technology mixing (WebFlow & AngularJS in this case) where doesn't makes sense.
Last thing, you and your team can discuss the possibility to develop an Angular based single page application which consumes a server side API coded in Java.
It is too late but might be useful for someone looking for this sort of answer.
I would recommend
Angularjs SPA(single page application) and use html template instead jsp.
Implement Token based authentication rather session based and implement restful spring web mvc api.
web flow/navigation can be controlled using the Angular services or browser's localstorage. I would recommend Angular services to manage app state instead browser localstorage.
And obviously bootstrap 3 to make the UI pretty.
Example implementation: jhipster
I have been doing some research about spring web flows and have some questions for which I cannot find any clear answers.
Question 1: Does Spring Web Flow replace a simple MVC Controller? Can we have a simple MVC Controllers and Web flow configured in one project?
I withdraw question 2 as I was looking at documentation for a Spring web flow 2.0.9.
you can do anything with spring MVC,web flow often use to reduce flow base code such shopping car ,for example If you want implement shopping cart you have to write controller code for each step,even if you are not using database ,that take too long time to get parameters and path again to view response and hold them in DOM ,Web flow help you to keep this information
until flow going to be finish,
But in spring ,Java server face is base on web flow.
Web Flow can not replace in all manner with MVC, for some reason:
1-MVC architecture helps isolate between html designer and java developer ,in web flow you can not do this!
2-In MVC you can make layers such database layer, business layer,service layer in simple way ,It reduce complexity of program ,and reuse again in other controllers injecting same service trigger, in Web flow ,trigger depend on flow step,you can use it again but in less functionality,for example you can not inject controller from controller.
3-Ajax in spring 3 has killer usage,I prefer Jquery response body over JSF ajax usage
If you are using Spring MVC, it will completely replace simple MVC structure, however you must have knowledge of Simple MVC as well. Refer documentation
http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/mvc.html
And model is a part of Spring MVC you can find it in document. However I did not get your 2nd question.
im using spring MVC and webflow to create a game server and serve some web pages to the users. Thing is, the javascript game will also make multiple ajax calls to restful services on the same server for some game logic. While the web page serving performance is not critical, the restful service calls need to be as efficient as possible (efficient as in response time).
For performance of the services, would it be better to use pure JAX-RS (jersey) web service calls without the spring ws overhead (since i understand the spring layer could affect performances negatively) or would it be the same if i used the spring webservices framework instead and maintain integration with the rest of the spring family?
thanks!
There aren't many clear benchmarks out there, but take a look here:
http://www.techempower.com/benchmarks/
It clearly shows the overhead of using Spring. Compared to Servlets that serve JSON manually Spring is "slower". Personally, I don't think that Spring cuts development time, unless you are very much familiar with it. Creating a simple servlet that will act as a REST API is very simple. Take a look at the servlet code from the benchmark:
Servlet benchmark
I don't think Spring per se will affect performance negatively. Where did you hear that?
Spring web services are "contract first" SOAP services. If you're saying that you don't want to pay the overhead of SOAP, XML, marshalling and unmarshalling, then you have a valid point. That's true whether you use Spring to implement the services or not.
REST is HTTP, so it's a natural for AJAX calls.
I believe Spring 3.0 supports REST, so it's not a "Spring or not Spring" choice:
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/new-in-3.html#d0e1188