Can we use angular2 universal with server side JAVA

情到浓时终转凉″ 提交于 2019-12-07 03:58:49

问题


I have an web project which is using angular 2 on front end and java spring 4 on server side. I am somewhat new to angular 2. I wanted to use angular universal for prerendering. How can i able to achieve it?

is there any tutorial which explains it with Java on server side?

Is there any other library that will help me out?


回答1:


Fortunately their's a library (Angularj-Universal) or a solution for rendering Angular4 applications on the server side (Spring Boot or Java EE) and sending them to the browser as 'already-bootstraped' application.

Angularj-Universal library is a server side rendering for Spring Boot and Angular4 based on the J2V8 library, also you can implement your own render implementation.

On the home page of this project you will find a useful guides step-by-step on how to create angular application from scratch and integrate it with Spring Boot using @angular/cli




回答2:


Angular 2 Universal works with nodejs/asp.net only.

You could use java server for rest api and separate nodejs server for pre-rendering or play with v8 jni bindings.

https://github.com/angular/universal#getting-started




回答3:


Unfortunately there are not much support available for now.

Angular Universal was originally built to work with a node.js back-end. There are adapters for most popular node.js server-side frameworks such as Express or Hapi.js. In addition to node.js, however, Angular Universal has ASP.NET Core support. In the near future we hope to add support for Java, PHP and Python. -Related page-

You can follow this issues (spring boot support & java backend) on github.
Additionally, check out this libraries;

  • J2V8 A Highly Efficient JS Runtime For Java
  • Java's Nashorn Javascript engine (link1)



回答4:


Not sure if you are looking for this but here is something that might help you

Since you want to deploy your angular app within spring-boot app follow these steps

  1. Create a public folder under resources in your spring-boot project

  2. ng-build --prod, type this command on you angular project which will create a dist folder under your angular project directory

  3. copy files from you dist folder and place it in public folder under resources of your spring-boot project.

This will help you run your angular-app under spring-boot.



来源:https://stackoverflow.com/questions/37699744/can-we-use-angular2-universal-with-server-side-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!