How to integrate an Angular 4 application with the Spring loading stack?

I would like to integrate the Angular 4 client application with the Java Spring application running on http://localhost:8080/and offering some rest points of rest. My goal is to be able to call an Angular application from a URL, for example http://localhost:8080/adminisitration. How can i do this?

Thanks in advance,

+6
source share
5 answers

You will need to create an ng application and place it in the spring-boot folder

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 angular-app under spring-boot.

http://localhost:8080/adminisitration,

+1

,

angular cli (, ... .. ), maven pom.xml.

+2

angular spring , , , .

-, angular nginx spring angular -, nginx,

location /api/ { proxy_pass http://localhost:8080/api/; }

, angular GET http://localhost/api/somerest, GET http://localhost:8080/api/somerest

+1

, - angular 4 java spring.

java spring app - API, angular 4 (angular -cli proxy → ).

Angular 4 node.js, java spring tomcat (), eclipse. (, angular 4 localhost: 4200, java spring API http://mydomain.ch:8900)

, .

PS. proxy (angular 4 ) (java spring)

0

, proxy.config.json , .angular-cli.json

{
  "/": {
    "target": "http://localhost:8080",
    "secure": false,
    "logLevel": "debug"
  }
}

URL- backend http://localhost:8080/administration /administration, http://localhost:8080/ . app.component.ts ngOnInit()

this.http.get('/adminisitration',someRequestOption).subscribe(res =>{
  console.log('happy...!');
})

-: (tomcat 8080)

: ng serve --proxy-config proxy.config.json url http://localhost:4200, , .

Note: above the default ports, as provided by spring boot and angular 4

0
source

All Articles