Reputation: 41
I've developed a REST API for an AngularJS application using Spring Boot. I'm running Java 8 and deploying to Tomcat 8 on Ubuntu, running Oracle's JDK8. Everything works just fine when I run from within Eclipse, or if I run the application as a JAR. If I hit localhost:9000/api I'll get output such as:
{
"expenses" : {
"href" : "http://localhost:9000/api/expenses"
},
"expenseTypess" : {
"href" : "http://localhost:9000/api/expensetypes"
},
....
}
If I package up the application as a WAR and deploy it on Tomcat at /myapplication, I lose the trailing slash after the application root. Calls to 192.168.1.170:8080/myapplication/api returns:
{
"expenses" : {
"href" : "http://192.168.1.170:8080/myapplicationapi/expenses"
},
"expenseTypess" : {
"href" : "http://192.168.1.170:8080/myapplicationapi/expensetypes"
},
....
}
...which obviously causes everything to explode since none of the API links are correct. If I manually invoke the correct URI, then the returned resources also have corrupted links.
Has anyone seen this and overcome it?
Upvotes: 1
Views: 446
Reputation: 41
Well, the answer was really simple. So simple, I neglected to even think about it. I had defined a base URI for the API in application.properties as:
spring.data.rest.base-uri=api
Changing to:
spring.data.rest.base-uri=/api
fixed the problem :/
Upvotes: 1