Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat using war name as base url for Spring boot

I have a spring boot application named "springapp" which has a base URI as:

 http://localhost:8080/

When I run it as a standalone application it is working fine. But when I run it like "run as --> Run on Server" in Eclipse, it would append the war name as springapp-1.0-snapshot and the base URL would become:

 http://localhost:8080/springapp-1.0-snapshot

Is there any way I could fix this. I want the URI to be

 http://localhost:8080/springapp

I tried all below configurations in my application.properties but none of them worked:

 spring.webservices.path=/springapp
 server.tomcat.basedir=/springapp
 spring.jersey.application-path=/springapp
 server.contextPath=/springapp
 server.servlet-path=/springapp

This is my starter class:

    @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
    @ImportResource("classpath:spring-config.xml")
    public class SpringAppStarter extends SpringBootServletInitializer {

        private static final Logger GENERAL_LOG = LogManager.getLogger(SpringAppStarter .class);

        @Override
        protected SpringApplicationBuilder configure(
                SpringApplicationBuilder application) {
            return application.sources(SpringAppStarter.class);
        }

        public static void main(String[] args) {
            // TODO Auto-generated method stub
            GENERAL_LOG.info("Starting Spring  Service App");

            SpringApplication.run(SpringAppStarter .class, args);
        }
    }

and my request mapping class:

 @RestController
 @RequestMapping("/Customers")
 public class SpringAppResource {
    @RequestMapping("/")
    public String index() {
        return "Greetings from Spring Boot!";
    }
 }

I also addded context configuration in the META-INF folder as:

 <Context>
     <context docBase="springapp" path="/springapp" reloadable="true"/>
 </Context>

I am using Maven to build the project. And I do not want to change the service name. I need to provide the context path in the application itself somewhere. There cannot be any dependency on server. I am supposed to provide all configurations, so after deployment no configuration needs to be made.

like image 991
Madie Avatar asked Mar 12 '23 04:03

Madie


1 Answers

You can also change the app name on Tomcat server as:

  1. Double click your server instance in "Servers" view
  2. Switch tab from "Overview" to "Modules" (at the bottom of the configuration screen)
  3. Select your application in the list and click "Edit" on the right hand side
  4. Set "Path" as "springapp" (or any name you want for the URI)
  5. Click "OK" and save the changes.

Now your app will be at the URI: http://localhost:8080/springapp

like image 143
Bahadir Tasdemir Avatar answered Mar 13 '23 23:03

Bahadir Tasdemir