Default Web Application URL - spring

Currently, the default url for my sample application is:
http://127.0.0.1:8080/SpringMVC/
Is it possible for my to access it through below url ?
http://127.0.0.1:8080/
How can this be done ?

rename the war file to ROOT.war . Then delete (or rename) the default ROOT tomcat directory and start tomcat.

Related

SOLVED - Where to place a file for CloudRun to access the file with a Spring Boot application deployed in CloudRun

I am new to GCP/SpringBoot and working on a project where I have a scenario to read a file that is present in the project directory. The below code works fine when I run it with localhost but fails with "File not Found" after deploying the Springboot application to cloudrun.
Can anyone help on how to read the file or what is the location to place the file.
InputStream is = new FileInputStream("Legend.jpg");
Intead of put the file at the root of the project, it's better to use resource files.
You can put your file in the resource folder src/main/resources/images/Legend.png
And retrieve it in the jar as follow :
InputStream stream = ResourceUtil.class.getClassLoader().getResourceAsStream("images/Legend.png");
You can also check this topic to have more explanations on different ways of retrieving files from resource folder.

Deploying azure tomcat 9.0.62 app service maps all webcontent subfolders paths to root

When creating a tomcat app service I create subfolders in webcontent and their path is created accordingly. Example tree:
Webcontent:
index.jsp
folder1:
page.jsp
To access page.jsp url I type: website.com/folder1/page.jsp
This all works as expected in localhost on any tomcat version, however when I deploy it to azure app service Tomcat v9.0.62 page.jsp is mapped to root: website.com/page.jsp
If I downgrade to tomcat v9.0.54 it works as expected.
I'd really appreciate any help in figuring out how to fix this behavior when deployed

set tomcat response header location as absolute path instead of relative path

In my spring application after upgrading to tomcat8 response header location is become relative path. Can i know which file should i config for changing it back to absolute path.
As we are using nginx server and alb in our application. relative path response returning 404 page in nginx url were it is working fine in alb .
Set <Context useRelativeRedirects="false"> in context.xml of tomcat folder.
Reference :
https://tomcat.apache.org/tomcat-8.5-doc/config/context.html

can't access to html file tomcat

I have an html file in my app root folder, which is located under webapp tomcat folder: apache-tomcat-9.0.0.M3\webapps\shop\index.html
when I'm trying to open http://localhost:8080/shop/
"The requested resource is not available"
occurs. I'm using spring mvc, so I'm getting the following message in terminal: No mapping for http request with URl shop/ in DispatcherServlet. Nevertheless it works fine if rename it to index.jsp

tomcat published two projects under path "webapps/"

I modified the file conf/server.xml like this below
<Context path="AA" docBase="BB" reloadable="true" />
when I start tomcat from a shell file publish.sh:
#!/bin/bash
#defined
TOMCAT_HOME="/root/software/apache-tomcat-7.0.29"
#start tomcat
cd "$TOMCAT_HOME"/bin
sh startup.sh
echo "tomcat is starting,please try to access $PROJECT console url"
tomcat publish two projects under path "webapps/",AA and BB。And I tracked that BB was published after AA.
If you logged on the terminal , and start tomcat directly in the directory "$TOMCAT_HOME"/bin with command:
>./startup.sh
Only one project "BB" under path "webapps/"。
Who can tell me Why? Thanks!
You have double-deployed your web application.
How? Well, you put BB.war into webapps/ (which will be auto-deployed to /BB) and then you put <Context path="AA" docbase="BB"> into server.xml which deployed BB.war to /AA. What did you expect?
If you just want your application to be deployed to /AA, then just re-name the WAR file to AA.war and be done with it: take-out the <Context> in server.xml because it's just making your job harder. This is why it's explicitly recommended not to do that.

Resources