I am running a springboot application and I ran it two ways:
1) running the spring boot app within eclipse run as -> application and selecting the Application.java for the spring boot app and running it in Eclipse itself. All the POST requests I am sending to it work perfectly fine.
2) compile the spring boot into a jar and then run it as java -jar <>.jar. The application starts fine but only SOME of the POST requests work this time.
Is there a reason why this could be happening? I am not sending the requests differently in either case. In the second case, I am getting a 500 error
OK I figured out the issue, I have an angular frontend where I am passing in Typescript objects back to the server which Spring then automatically maps to POJOs. For some reason, this mapping was working when I ran the application in Eclipse as an Eclipse application, but not when I ran the packaged JAR as a standalone server.
This is the reason behind the error, but if anyone can shed light on WHY this difference in mapping exists, it would make this less painful.
Related
My front-end is a Nuxt App and API is Spring boot. In my local development environment everthying works fine. However after hosting both applications on Heroku, couple of URLs are returning 404 pages.
In Heroku logs for my API, I noticed that when I click on admin/tours or admin/bikes page they should fetch data from /tours and /bikes endpoints but it never registers the path.
First I thought, it was a problem with my front end code. But routes are working fine in local environment.
Then I thought it was something with API. But when I manually hit the hosted API route on browser it is working fine too.
Building the app and running on production mode in local machine also working fine.
I can't figure out why It never hits those two routes but others.
Have you added the 'Procfile' to the root of your Spring Boot application?
I ran into a similar issue last year and I added a 'Procfile' (with no extension) to the root of my Spring Boot app and it solved it.
Add this line to your 'Procfile'
web: java $JAVA_OPTS -Dserver.port=$PORT -jar target/*.jar
More information here: https://devcenter.heroku.com/articles/java-support#default-web-process-type
I finally figured it out.
I have pages in pages directory called bikes and tours.
I also have pages in pages/admin directory called bikes and tours.
Even though technically my routes are fine, when building on Heroku it renames index.vue files inside admin directory to Index.vue to differentiate the pages.
The fix is to rename pages in one of the directories or name the pages differently by passing a name option inside pages.
My application has two separate parts, back-end in Java (Spring boot) and front-end in Vuejs.
I can simply deploy the JAR for my back-end code where I need to, and that's it for deployment.
But when it comes to deploying the Vuejs app, I can do something similar and just put the compiled Vuejs application in the proper path in a Java Spring boot application and that will be all for the front-end too.
It just doesn't seem right to me to put that application in Spring boot when it doesn't really have to do anything with it really other than for deployment (Maybe I know nothing like Jon Snow).
Also, when its put under a Spring boot application, manual URL editing doesn't work.
This app doesn't do anything on its own, it fetches all its data from the back-end app.
So what are my options here, can someone please guide me in the right direction?
Do I just setup a nodejs server and deploy the Vuejs app in that? I am not sure how that works, or whether should I even be doing that for a production application. And if so, where do I start with setting up nodejs?
It makes sense to deploy it together with spring, and it's very common practice, at least from my experience with Angular (which I suppose would be very similar to VueJS).
You don't need to have 2 servers running. You just let Spring server your HTML/js/CSS files, which helps you avoid any problems with CORS.
I am not really sure what 'URL manual editing', do you mean by navigating the web page by editing the URL? I don't see much use cases there tbh and I would guess that is only a matter of few settings.
In gradle - I would set up a build task (not sure if task is correct word, 2 build.gradle files, each for FE/BE, the BE would depend on FE), the FE would be run when BE is run, it creates static HTML/js (in my case from angular, but it should be similar for Vue) and BE task adds the output to the classpath of the java application so that Spring can register the HTML and serve it to you.
You could use Docker to create a Dockerized version of your Vue.js app and then you can deploy this onto a cloud service provider such as AWS (e.g. EC2).
Check out this link for a basic guide https://v2.vuejs.org/v2/cookbook/dockerize-vuejs-app.html
My approach is to deploy front-end and back-end separately.
You can use web-server to proxy requests to Vuejs or Spring boot.
For example, if you use Nginx, you can use this configuration to pass requests
# pass root request to index file
location / {
root /front_files/;
index /index.html;
}
# pass requests to static files
location ~ ^/(js|styles) {
root /front_files/;
}
# pass requests to back-end
location /api/ {
proxy_pass http://127.0.0.1:8080/;
}
I am taking over an old colleague's code and he used JHipster to build a Maven-Spring-Angular project.
I am able to compile, package his code and I used a simple Chrome Web Server (plugin), point it at the project's "target" folder which contains all the web components (i.e. assets, bower_components, META-INF, WEB-INF, etc) and his code, a dashboard can run successfully on the Chrome Web Server.
Problem is, all API calls to the Java back-end are failing.
IMAGE: API calls 404 error
IMAGE: Sample endpoint, api/data
Am I missing any steps when trying to run the project locally on my PC?
Will update the answer in details soon but just want to share the solution.
Chrome Web Server is not a proper Servlet Container hence Spring wasn't able to start. Since Spring did not start, requests to the endpoints could not be handled.
I have been struggling with the creation of a SOAP web service and I simply can't get it working.
I have written my service, and then, from Eclipse, I created a Web service. And although the saving in the db worked just fine when I tested the service locally (created a simple main method), when I try testing it from the generated Web service I get NoClassDefFoundError.
If anyone has the time to take a look I would be gratefull.
https://dane289#bitbucket.org/dane289/soapservice_problems.git
Thank you in advance!
The problem was that eclipse was not adding the jars to the WAR file.
After adding them to the war via the eclipse menu Assembly something everything worked fine.
I have with me the client interface for a web service that was built using JBoss/RESTeasy. The web service calls work fine when they are invoked from a stand-alone app, but as soon as I put them into a webapp running in a Tomcat container (on the same machine), they start behaving weirdly. Some of the calls return empty results while some others simply fail with this exception:
org.jboss.resteasy.client.ClientResponseFailure: Error status 404 Not Found returned
Any idea of what might be going on? Could this be a result of a library conflict? All the required client libraries are in the WEB-INF/lib directory of the webapp.
Seems that your services are not deployed properly. Take a look at your catalina.out or some other logs for more details.