2
votes

I have spring boot application and angular js project as two different modules.

The angular js contents ( files inside 'dist' folder) are converted as jar files and included as part of Spring boot application. The folder structure inside the jar is /static/**.

The jar appears inside the lib folder of the spring boot application.

Now when i try to access the application http://localhost:8080, i get 404 error.

It works fine, if i copy the "dist" folder content inside the /resources/static and create spring boot jar file.

Am i missing anything when the static contents are included as jar file. ?

Thanks in advance

2
Static content in spring boot should be exists under the /resources/static folder only, and angular files are considered to be static content. Move the content of dist folder to the /resources/static folderMoshe Arad
any updates? I am facing the same issues... after ng build , using maven i put all files under /BOOT-INF/classes/ but still its not accessible using URL.ammu

2 Answers

0
votes

I have a similar set up like you but using Angular 4. My Spring Boot version is 1.5.3.RELEASE.

My build is based on Maven with two modules. One for front-end (JAR) and one for backend (WAR), which references first module with Maven dependency mechanics.

Providing static content works out of the box. Since I'm using Spring Security I have to configure access rules for this resources. But this issue should be answered with a 401 and not 404.

Your angular JAR structure seems to be correct. Is your front-end build complete?

The lib folder with the front-end JAR is in my Spring Boot WAR on path /WEB-INF/.

Did you check if there is a bug connected with your used Spring Boot version?

0
votes

@Moshe Arad @Raj In my understanding from https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot , the static contents can be in one of those mentioned locations. However, I myself is facing struggle in serving static content. I was working on spring-boot and angular-cli(6.1.5) based app. For deploy purpose, so that UI works on spring-boot port; I ran ng build. It generates files in src/main/resource/static (changed outputPath in angular.json to resources/static and create an empty dir static in resources) . But spring-boot didn't serve any angular content at 8080. Although index.html has <base href="/">, I thought to be more specific for it to pick/serve .js contents from static dir so I ran : ng build --base-href / --deploy-url /static/ . This time the generated index.html has /static/runtime.js etc. in . But when accessing localhost:8080/ (right click -> inspect shows 200 response code) still doesn't show any UI content. But hitting localhost:8080/static/runtime.js shows 404 .

I believe there is more to do beyond just adding content to resources/static as probably tomcat is trying to serve it but somehow the content not being displayed. Because I do notice favicon icon (angular icon) on browser tab and the contents of jar file shows generated static files in the path (BOOT-INF/classes/static/index.html etc.)