问题
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
Create a public folder under resources in your spring-boot project
ng-build --prod, type this command on you angular project which will create a dist folder under your angular project directory
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