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.
You can also change the app name on Tomcat server as:
Now your app will be at the URI: http://localhost:8080/springapp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With