0

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);
    }
}

  • I suspect your migration is going wrong. What does your application.properties look like. What did your application look like (especially the webapplicationinitializer you had and now should be replaced with extending the `SpringBootServletInitializer`). – M. Deinum Feb 23 '23 at 12:19
  • @M.Deinum i have added the files which you have requested – suhail ahmed Feb 23 '23 at 16:00
  • How is the war file generated? Are there more wars under /webapps? Did you added /changed `context.xml` files somewhere? BTW, app could be accessible at localhost:8080 – LMC Feb 23 '23 at 19:40
  • @LMC i have generated war file using maven. there is only one app in webapps and i havent changed context.xml and i cant able to access at localhost:8080 – suhail ahmed Feb 24 '23 at 03:50

1 Answers1

0

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.