r/SpringBoot • • Aug 03 '24

Deploying of a spring boot &angular app

Hi I created a spring boot & angular application with mysql as a database and i want to learn how to deploy it. Is there any videos or articles I can follow because honestly i do not have any idea where to start from

24 Upvotes

14 comments sorted by

7

u/bikeram Aug 03 '24

There's a few ways to do this.

My current method is using maven's frontend-maven-plugin. Maven compiles my Vue code, then copies it into my springboot target. This means my springboot.jar has everything. Then I can build a single docker container to deploy.

The other way to do this would be build a nginx container with all of your static angular code. Then reverse proxy to your springboot container.

On second thought, I'll throw together a repo. This can get pretty involved.

1

u/Dull_Specific_6496 Aug 03 '24

Thanks alot, i've never used docker before so i'll have to do some research

5

u/bikeram Aug 03 '24

https://github.com/santa-cruz07/springboot-frontend-example/tree/main

I'm heading to bed. I'll finish this over the weekend, but the major parts are there.

Pull the repo and look at

SpaRedirectFilterConfiguration.java

That's class has the magic to pass anything inside of REGEX to springboot. So you'll notice all my spring endpoints start with /api/.

Then vue uses /management/* for all of its routes.

You'll also need the vue/src/assembly/dist.xml and the vue/pom.xml build plugins.

The docker-compose, docker-files, and github actions are there too.

1

u/g00glen00b Aug 03 '24

I usually do something similar, but turn the frontend into its own Maven module and include it as a Maven dependency. https://dimitri.codes/bundling-react-spring-boot/

2

u/MartinPeterBauer Aug 03 '24

You build the angular App into backend static of Public folder. You say mvn package. Thats the build

Deploy means somehow copying the jar to a Server. You can do IT manually or with ci tools

1

u/wpfeiffe Aug 03 '24

This. I do the same with gradle. I also wrapper the npm build commands for angular app such that full build can be done from single task. I’ve seen this done in maven as well.

Then the question becomes what is the best way to deploy a spring boot app. Lots of answers to that in this subreddit.

2

u/Glad_Mycologist_3528 Aug 03 '24

There are multiple ways If u are on Cloud, u can choose plan platform as a service provided by the cloud provider, in this plan, Cloud will provide you a virtual machine + runtime environment (JRE or JDK) ready to use and u need just to upload JAR file.

An example of this on Azure is App service

For the front end, you can build your project and upload files, js, and html css to Cloud CDN, like S3 on AWS.

For the Databse, the cloud provider can provide for you a database server ready like RDS on AWS.

The second way is to purchase a VPS and install on it JAVA, MySQL, and Nginx or Apache to serve the front end.

Run your JAR file on the server as a linux service using SystemD or initD

https://docs.spring.io/spring-boot/docs/1.4.0.RC1/reference/html/deployment-install.html#deployment-service

Upload you build front to Nginx

1

u/Dull_Specific_6496 Aug 03 '24

Thanks i'll try it

2

u/MoreCowbellMofo Aug 03 '24

I did it by following this but it took me abt a week to get together all the relevant config for it to work as I have no idea abt vpcs https://spacelift.io/blog/terraform-ecs

Looking at it now I probably didn’t copy it correctly as I already had one part deployed to an ec2 instance that was publically visible but wanted ecs clusters that run on ec2 instances.

The cost is abt $15/month but it means if I need to scale I can do so easily.

My angular app has nginx in front of it but I’m not entirely sure how necessary it is. The spring boot back end is a separate task definition that’s run by the ecs service (which is what keeps the task up if it fails for any reason).

1

u/MeowManMeow Aug 03 '24

This is a starter I created. It uses React instead of angular but it has docker and even cloud formation if you are going to use AWS. https://github.com/MannanM/spring-boot-react-maven-starter