Home > Software engineering >  why 404 after ng build?
why 404 after ng build?

Time:09-17

I have an angular/spring boot app. Normally I use maven to build both using mvn clean install from the parent dir. That packages up the front and back ends into single jar file. Then I run that jar file with java -jar appname.jar. This works fine most of the time. But every so often, the angular front end stops updating the changes I make.

I googled this a while back and the solution was to do ng build --output-hashing=all. This usually works, but not this time. Now I'm seeing 404 error. Seems there is some resource its not finding.

2021-09-08 08:33:46.520 DEBUG 93888 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped to ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"] 2021-09-08 08:33:46.528 DEBUG 93888 --- [nio-8080-exec-1] o.s.w.s.r.ResourceHttpRequestHandler : Resource not found 2021-09-08 08:33:46.529 DEBUG 93888 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed 404 NOT_FOUND

Thinking some resource might be missing, I tried npm install and ng build, but same result.

If I go back to the master branch, build it, go back to the dev branch, build it, then the 404 goes away but I'm back to the original problem.

Suggestions?

CodePudding user response:

try using base href while using ng build ng build --prod --base-href './' base href will change based on your app context. i.e it could be './app' or './myapp/app' , check from console the difference in path and add it in context

CodePudding user response:

The solution was to delete the dist folder, then do a ng build, then do a mvn clean install. Its working now.

  • Related