springspring-boottomcattomcat10

War name is appending twice while accessing the application using war name in tomcat 10


I had a spring 6 application which is being migarted to spring boot 3.

i have replaced all the xml based configuration using spring boot annotations.

then i am trying to deploy spring boot application as a war file on tomcat 10. I am copying the war file and placing in the webapps folder in tomcat then application is getting started when i run "cataline.sh start". but when i try to access the deployed application using the war name

http://localhost:8080/war-name-1.0.0

then im facing 404 error

2023-02-23T16:02:51.284+05:30  INFO 10708 --- [nio-8989-exec-2] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2023-02-23T16:02:51.285+05:30  INFO 10708 --- [nio-8989-exec-2] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms
2023-02-23T16:02:51.307+05:30  WARN 10708 --- [nio-8989-exec-2] o.s.web.servlet.PageNotFound             : No mapping for GET /war-name-1.0.0/war-name-1.0.0/
2023-02-23T16:02:51.308+05:30 ERROR 10708 --- [nio-8989-exec-2] o.s.b.w.servlet.support.ErrorPageFilter  : Cannot forward to error page for request [/index.html] as the response has already been committed. As a result, the response may have the wrong status code. If your application is running on WebSphere Application Server you may be able to resolve this problem by setting com.ibm.ws.webcontainer.invokeFlushAfterService to false

i want to able to access the application using the war name like below

http://localhost:8080/war-name-1.0.0

i want to able to access the application using the war name like below

http://localhost:8080/war-name-1.0.0

My properties file contains

spring.jmx.enabled=true
server.port = 9292

my main class looks like below

   @SpringBootApplication
public class MyApplication {
   public static void main(String[] args) {
       try {
           SpringApplication app = new SpringApplication(MyApplication.class);
           app.run(args);
       } catch(Throwable ex) {
           ex.printStackTrace();
       }
   }
}

My servlet initializer looks like below.

public class MyServletInitializer extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(MyApplication.class);
    }
}


Solution

  • The issues was with the filters

    i am using following line

    request.getRequestDispatcher(URLDecoder.decode(uri, "UTF-8")).forward(request, response);
    

    to transfer the request to the servlet by calling the getRequestDispatcher so when i pass /war-name/endpoint to getRequestDispatcher then it appending /war-name/ to the request and looking for the servlet with name "/war-name/war-name/endpoint which wont be available so i have received 404.

    to solve it i have removed /war-name/ from the uri which is passed to getRequestDispatcher . now it able to identify the servlet and forward the request to it.