springboot之端口设置和contextpath的配置方式

目录
  • 端口设置和contextpath的配置
    • 端口设置
    • ContextPath配置
  • Springboot中添加contextPath
    • profile配置

端口设置和contextpath的配置

端口设置

Spring boot 默认端口是8080,如果想要进行更改的话,只需要修改applicatoin.properties文件,在配置文件中加入:

server.port= 9090

常用配置:

########################################################
###EMBEDDED SERVER CONFIGURATION (ServerProperties)
########################################################
#server.port=8080
#server.address= # bind to a specific NIC
#server.session-timeout= # session timeout in seconds
#the context path, defaults to '/'
#server.context-path=/spring-boot
#server.servlet-path= # the servlet path, defaults to '/'
#server.tomcat.access-log-pattern= # log pattern of the access log
#server.tomcat.access-log-enabled=false # is access logging enabled
#server.tomcat.protocol-header=x-forwarded-proto # ssl forward headers
#server.tomcat.remote-ip-header=x-forwarded-for
#server.tomcat.basedir=/tmp # base dir (usually not needed, defaults to tmp)
#server.tomcat.background-processor-delay=30; # in seconds
#server.tomcat.max-threads = 0 # number of threads in protocol handler
#server.tomcat.uri-encoding = UTF-8 # character encoding to use for URL decoding

ContextPath配置

Spring boot默认是/ ,这样直接通过http://ip:port/就可以访问到index页面,如果要修改为http://ip:port/path/ 访问的话,那么需要在Application.properties文件中加入server.context-path = /你的path,比如:spring-boot,那么访问地址就是http://ip:port/spring-boot 路径。

server.context-path=/spring-boot

常用配置:

########################################################
###EMBEDDED SERVER CONFIGURATION (ServerProperties)
########################################################
#server.port=8080
#server.address= # bind to a specific NIC
#server.session-timeout= # session timeout in seconds
#the context path, defaults to '/'
#server.context-path=/spring-boot
#server.servlet-path= # the servlet path, defaults to '/'
#server.tomcat.access-log-pattern= # log pattern of the access log
#server.tomcat.access-log-enabled=false # is access logging enabled
#server.tomcat.protocol-header=x-forwarded-proto # ssl forward headers
#server.tomcat.remote-ip-header=x-forwarded-for
#server.tomcat.basedir=/tmp # base dir (usually not needed, defaults to tmp)
#server.tomcat.background-processor-delay=30; # in seconds
#server.tomcat.max-threads = 0 # number of threads in protocol handler
#server.tomcat.uri-encoding = UTF-8 # character encoding to use for URL decoding

Springboot中添加contextPath

spring boot默认是/ ,这样直接通过http://ip:port/就可以访问到index页面,如果要修改为http://ip:port/path/ 访问的话,那么需要在Application.properties文件中加入server.context-path= /你的path,比如:spring-boot,那么访问地址就是http://ip:port/spring-boot路径。

profile配置

server.context-path=/spring-boot
server
     context-apth: /spring-boot

以上为个人经验,希望能给大家一个参考,也希望大家多多支持我们。

(0)

相关推荐

  • Springboot之修改启动端口的两种方式(小结)

    Springboot启动的时候,端口的设定默认是8080,这肯定是不行的,我们需要自己定义端口,Springboot提供了两种方式,第一种,我们可以通过application.yml配置文件配置,第二种,可以通过代码里面指定,在开发中,建议使用修改application.yml的方式来修改端口. 代码地址 #通过yml配置文件的方式指定端口地址 https://gitee.com/yellowcong/springboot-demo/tree/master/springboot-demo2 #硬

  • SpringBoot项目修改访问端口和访问路径的方法

    创建SpringBoot项目,启动后,默认的访问路径即主机IP+默认端口号8080:http://localhost:8080/ 此时,我们就可以访问Controller层的接口了,如:http://localhost:8080/hello package com.springboot.test; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.a

  • springboot 如何设置端口号和添加项目名

    1.修改全局配置文件(application.yml) server: port: 9001 servlet: context-path: /userRight [坑]SpringBoot 指定服务项目名 使用不同SpringBoot版本,指定访问项目路径的项目名,使用的配置也不一样 有网友指出 SpringBoot版本 配置 1.x server.context-path=/demo 2.x server.servlet.context-path=/demo 以下为本地测试可行代码 pom.x

  • springboot之端口设置和contextpath的配置方式

    目录 端口设置和contextpath的配置 端口设置 ContextPath配置 Springboot中添加contextPath profile配置 端口设置和contextpath的配置 端口设置 Spring boot 默认端口是8080,如果想要进行更改的话,只需要修改applicatoin.properties文件,在配置文件中加入: server.port= 9090 常用配置: ###################################################

  • Springboot启动不检查JPA的数据源配置方式

    目录 Springboot启动不检查JPA的数据源配置 1.问题 2.方案 设置Springboot项目忽略JPA启动 解决方案 Springboot启动不检查JPA的数据源配置 1.问题 有时我们使用spring boot ,在依赖中配置了spring data jpa的依赖,此时spring boot启动时会自动检测数据源的配置,如果没有则报无数据源的错误. 但是这个依赖必须要有,因为代码需要根据一些条件选择是否启用数据源,则么办? 2.方案 在SpringApplication实例中设置如

  • springboot 返回json格式数据时间格式配置方式

    目录 返回json格式数据时间格式配置 返回JSON日期格式问题 返回json格式数据时间格式配置 数据库里面查出来的时间是时间错格式,前段需要处理才能展示相应的格式,自己一个个转的话太麻烦,所以可以在apllication.property加入下面配置就可以 #时间戳统一转换 spring.jackson.date-format=yyyy-MM-dd HH:mm:ss spring.jackson.time-zone=GMT+8 其中time-zone是时区偏移设置,如果不指定的话时间和北京时

  • springboot 如何修改默认端口及application.properties常用配置

    springboot 修改默认端口及application.properties常用配置 Spring boot 默认端口是8080,如果想要进行更改的话,只需要修改applicatoin.properties文件,在配置文件中加入: server.port=9090 其他常用配置: (一).server配置 server.address #指定server绑定的地址 server.compression.enabled #是否开启压缩,默认为false. server.compression.

  • 如何设置springboot启动端口

    spring boot是个好东西,可以不用容器直接在main方法中启动,而且无需配置文件,方便快速搭建环境.可是当我们要同时启动2个springboot工程时,就会有问题,有可能会因为8080端口被第一个应用占用而导致第二个应用无法启动,这时就需要修改其中一个工程的启动端口. 可以通过实现EmbeddedServletContainerCustomizer接口来实现: public class Application extends SpringBootServletInitializer im

  • 详解SpringBoot初始教程之Tomcat、Https配置以及Jetty优化

    1.介绍 在SpringBoot的Web项目中,默认采用的是内置Tomcat,当然也可以配置支持内置的jetty,内置有什么好处呢? 1. 方便微服务部署. 2. 方便项目启动,不需要下载Tomcat或者Jetty 在目前的公司已经把内置的Jetty部署到了线上项目中,目前来说并无太大问题,内置就算有一些性能损失,但是通过部署多台机器, 其实也能够很轻松的解决这样的问题,内置容器之后其实是方便部署和迁移的. 1.1 优化策略 针对目前的容器优化,目前来说没有太多地方,需要考虑如下几个点 线程数

  • springboot学习笔记之 profile多环境配置切换的实现方式

    前言 一个应用程序从开发到上线,往往需要经历几个阶段,例如开发.测试.上线.每个阶段所用到的环境的配置可能都是不一样的,Springboot 应用可以很方便地在各个环境中对配置进行切换.所以,今天主要介绍Springboot profiles实现多环境配置切换. profiles多环境配置切换的四种方式 多个配置文件的方式yml 多文档块方式 设置程序参数 设置虚拟机参数 1.多个配置文件的方式 1.1.修改application.properties server.port=8080 1.2.

  • SpringBoot集成mqtt的多模块项目配置详解

    前言 近期为了准备毕设,准备使用SpringBoot搭建mqtt后端,本篇主要记录了在IDEA中搭建SpringBoot mqtt的多模块项目的过程 开发工具及系统环境 IDE:IntelliJ IDEA 2020.2 操作系统:Windows 10 2004 Java Version:1.8 SpringBoot Version:2.1.17.RELEASE 项目路径 Study |----study-common # 存放公共类 |----study-mapper # mapper层 |--

  • SpringBoot详细讲解多个配置文件的配置流程

    目录 配置文件加载顺序 验证 前期准备 验证配置文件加载顺序 验证属性互补 总结 一般情况下,springboot默认会在resource目录下生成一个配置文件(application.properties或application.yaml),但其实springboot允许配置多个配置文件(application.properties或application.yaml),但是这并不意味着这些配置文件一定会替换默认生成的配置文件,它们是互补的存在.如果在某些场景下需要把配置文件单独拿出来并且启动的

  • springboot+idea热启动设置方法(自动加载)

    springboot+idea热启动 1.在pom.xml中引入jar包 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency> 然后在build/plugins/plugin中设置

随机推荐