I am trying to learn Spring Framework and while going through the Spring MVC and Spring Boot REST to create a dummy project, I noticed below difference in the way the Tomcat responds to your URL in the browser
Spring Boot
http://localhost:8080/
Redirects to the Controller that is mapped to "/"
http://localhost:8080/springbootrestapp
where "springbootrestapp" is the project name, it gives HTTP 404 resource not found error
Spring MVC
http://localhost:8080/
Opens the Tomcat Home page
http://localhost:8080/springmvc
where "springmvc" is the project name, it redirects to the Controller that is mapped to "/"
My doubt is why in case of Spring Boot just entering the localhost:8080 redirects to the controller mapped to "/" whereas in case of Spring MVC(without Spring Boot configurations) it needs http://localhost:8080/<projectname>/ to redirect to controller mapped to "/" ?
I got the same issue In my case before running my Spring-MVC application I started the tomcat server I didn't stop so whenever I access localhost:8080/ it redirect me to Tomcat Client.
The first option is very basic: we just have to delete the /ROOT/ folder in $CATALINA_HOME\webapps, rename our springbootrestapp.war (or springmvc.war) to ROOT.war, and deploy it.
Our app will now be available at http://localhost:8080/.
There are different solutions not to change the filename. You can review the recommendations here.
Related
We have a web based application with Front end in Angular JS 1 and REST service with Spring jersey frame work.We are using Spring 3.We have deployed our project in Tomcat 9.We have deployed angular js part as a separate project and REST service is build as a war file and deployed separately.
Suppose our application url is https://10.100.200.300:8443/DEMO.When we are trying to access the URL with a wrong value say https://10.100.200.300:8443/DEMO_TEST we are getting the error 404 i.e. resource not found by the tomcat server.We want to show some customized error page for 404 or any other tomcat error. Please suggest how to do it?
You can have a look here - Configure spring boot to redirect 404 to a single page app
Make spring configuration as mentioned in above answer and reroute it to your desired page.
Currently I'm facing issue with redirecting application which is behind proxy server:
To see application I need to go to:
http://myserver.net/PREFIX/configuration
And I need to add PREFIX to every url which will be returned by spring. Currently after successful logging with spring security when I return
.successForwardUrl("/configuration")
It's redirecting me to url address which is not existing:
http://myserver.net/configuration
Is there any possibility to add Tomcat prefix to dispatcher servlet? To make somehow default path for the application:
http://myserver.net/PREFIX/
I was trying to use:
server.servlet.contextPath=PREFIX
But problem is that when I use context path, I need to go
http://myserver.net/PREFIX/PREFIX/configuration
To be redirected properly to spring controller. Maybe there is possibility to set up context path but only for response?
I am trying to use embedded forms with a start event with the Camunda spring boot starter.
My startEvent is described like this:
<bpmn:startEvent id="StartEvent_1" name="Rechnungseingang" camunda:formKey="embedded:app:forms/rechnungseingang.html">
<bpmn:outgoing>SequenceFlow_0dtfc1a</bpmn:outgoing>
</bpmn:startEvent>
The form itself is located under "src/main/webapp/forms/rechnungseingang.html", from my understanding this should be the correct path.
If I try to start the process after starting the spring boot app, I am receiving the error: "Form failure: The context path is either empty or not defined."
In the browser console, I can see a request to http://localhost:8080/test/api/engine/engine/default/process-definition/Rechnungseingang:1:927f0aa4-e590-11e7-973d-e2cbd8678b9f/startForm with the response:
{"key":"embedded:app:forms/rechnungseingang.html","contextPath":null}
Obviously the application can't handle the null value in the contextPath. How am I able to set the contextPath for Camunda in Spring Boot? In the application.properties I already tried to set server.context-path with no effect.
1.) there is no src/main/webapp with spring boot applications, use src/main/resources/static
2.) for camunda to link the resource to the engine, you will need a process application. This is done easily by adding "#EnableProcessApplication" to your spring boot app.
3.) Autodeployment requires a src/main/resources/META-INF/processes.xml file, but you can leave it empty
4.) there is a full example for embedded forms with camunda spring boot here: https://github.com/camunda/camunda-bpm-examples/tree/master/spring-boot-starter/example-twitter
My app is deployed at http://123.87.65.23:8080. The context path is /myapp configured in application.properties. So if I access http://123.87.65.23:8080, I get 404. but if I access http://123.87.65.23:8080/myapp/health, I get 200 as expected.
Our operation team monitors base url (http://123.87.65.23:8080) for 200 OK.
I have two options:
Return 200 OK when I hit http://123.87.65.23:8080. No response is required.
Or somehow proxy the request http://123.87.65.23:8080 to http://123.87.65.23:8080/myapp/health within my Spring Boot application.
NOTE: I am using embedded tomcat. so the option of changing server.xml is not applicable
I don't how know how to do either options.
If you set the contextPath attribute in your .properties file then Spring does what it's supposed to do, everything gets moved there.
If you're packaging the app as a .war and running it in an external server then you can set that server up to redirect root requests to whatever URL inside your Spring Boot application.
If you're packaging the app as a runnable .jar with an embedded server and you want to keep the contextPath in the .properties-level then
a) you still need some kind of external server that can catch requests to root and redirect to your Spring Boot application
b) you need to set up two distinct DispatcherServlets where one's contextPath is /myapp and the other's is / which will redirect to your Spring Boot Application
However, the easiest solution would be to remove contextPath and just prepend each Controller's #RequestMapping with /myapp, move all the management endpoints to /myapp with management.context-path and write a single #Controller method mapped to / that redirects to the health endpoint.
In your tomcat container your app should be deployed into a directory named "ROOT", not "myapp", if you wanna use root urls. And I guess your Dispatcherservlet may be configured to process requests to /health, and you need to process just /
Or maybe you've got a Controller, mapped to /health.
Can't tell anything else without code
If you want to get 200 on http://123.87.65.23:8080 request, you need an application named ROOT.war in your webapps folder.
So http://123.87.65.23:8080 and http://123.87.65.23:8080/myapp are two different applications.
I suggest you two options:
Deploy your application as http://123.87.65.23:8080 (ROOT.war)
Use some Proxy Server like nginx or apache. You can configure the proxy server to redirect all ROOT requests to you application
Here are some examples for nginx:
location / {
proxy_pass http://123.87.65.23:8080/myapp/;
}
or just return 200:
location / {
return 200;
}
I have created a new Appfuse 2.1.0 struts2 application and from the servlet i want to redirect to https://gmail.com, i have used the following code:
response.sendRedirect("https://gmail.com");
But this line was not working, my application was not redirecting to this domain which i have specified. Do i need to do any configurations to redirect to another domain from my appfuse application?
You need to give Url like:
response.sendRedirect("https:www.gmail.com");