Spring Boot How to change Context Path

摘要: In Spring Boot, to change the context path, update server.contextPath properties. The following examples update the context path from / to /mkyong or http://localhost:8080/mkyong

In Spring Boot, to change the context path, update server.contextPath properties. The following examples update the context path from / to /mkyong or http://localhost:8080/mkyong

Note
By default, the context path is “/”.

P.S Tested with Spring Boot 1.4.2.RELEASE

1. Properties & Yaml

1.1 Update via a properties file.

/src/main/resources/application.properties

server.port=8080
server.contextPath=/mkyong

1.2 Update via a yaml file.

/src/main/resources/application.yml

server:
  port: 8080
  contextPath: /mkyong

2. EmbeddedServletContainerCustomizer

Update via code, this overrides properties and yaml settings.

CustomContainer.java

package com.mkyong;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.stereotype.Component;
@Component
public class CustomContainer implements EmbeddedServletContainerCustomizer {
	@Override
	public void customize(ConfigurableEmbeddedServletContainer container) {
		container.setPort(8080);
		container.setContextPath("/mkyong");

3. Command Line

Update the context path by passing the system properties directly.

Terminal

java -jar -Dserver.contextPath=/mkyong spring-boot-example-1.0.jar

References

  1. Spring Boot – Embedded servlet containers

  2. Spring Boot – Externalized Configuration

  3. Spring Boot – How to change Tomcat port

上一篇: Spring Boot Hello World Example Thymeleaf
下一篇: Spring Boot Hello World Example Thymeleaf
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 


  • 微信公众号

  • 我的微信

站点声明:

1、一号门博客CMS,由Python, MySQL, Nginx, Wsgi 强力驱动

2、部分文章或者资源来源于互联网, 有时候很难判断是否侵权, 若有侵权, 请联系邮箱:summer@yihaomen.com, 同时欢迎大家注册用户,主动发布无版权争议的 文章/资源.

3、鄂ICP备14001754号-3, 鄂公网安备 42280202422812号