加入收藏 | 设为首页 | 会员中心 | 我要投稿 烟台站长网 (https://www.0535zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 编程要点 > 语言 > 正文

Spring Boot默许配置文件

发布时间:2023-06-13 09:31:51 所属栏目:语言 来源:未知
导读:   通常情况下,Spring Boot 在启动时会将 resources 目录下的 application.properties 或 apllication.yml 作为其默认配置文件,我们可以在该配置文件中对项目进行配置,但这并不意味着
  通常情况下,Spring Boot 在启动时会将 resources 目录下的 application.properties 或 apllication.yml 作为其默认配置文件,我们可以在该配置文件中对项目进行配置,但这并不意味着 Spring Boot 项目中只能存在一个 application.properties 或 application.yml。
  默认配置文件
  Spring Boot 项目中可以存在多个 application.properties 或 apllication.yml。

  项目根路径下配置文件 application.yml 配置如下。
  #项目更目录下
  #上下文路径为 /abc
  server:
    servlet:
      context-path: /abc
 
  项目类路径下 config 目录下配置文件 application.yml 配置如下。
  #类路径下的 config 目录下
  #端口号为8084
  #上下文路径为 /helloWorld
  server:
    port: 8084
    servlet:
      context-path: /helloworld
 
  项目类路径下的 application.yml 配置如下。
  #默认配置
  server:
    port: 8080
  
  在 net.biancheng.www.controller 包下创建一个名为 MyController 的类,代码如下。
  package net.biancheng.www.controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.ResponseBody;
  import org.springframework.web.bind.annotation.RestController;
  @RestController
  public class MyController {
      @ResponseBody
      @RequestMapping("/test")
      public String hello() {
          return "hello Spring Boot!";
      }
  }
 
  启动 Spring Boot,查看控制台输出。

(编辑:烟台站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章