加入收藏 | 设为首页 | 会员中心 | 我要投稿 上饶站长网 (https://www.0793zz.com.cn/)- 数据库平台、视觉智能、智能搜索、决策智能、迁移!
当前位置: 首页 > 综合聚焦 > 编程要点 > 语言 > 正文

Spring Boot默许配置文件

发布时间:2022-07-22 12:35:34 所属栏目:语言 来源:互联网
导读:通常情况下,Spring Boot 在启动时会将 resources 目录下的 application.properties 或 apllication.yml 作为其默认配置文件,我们可以在该配置文件中对项目进行配置,但这并不意味着 Spring Boot 项目中只能存在一个 application.properties 或 application
  通常情况下,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,查看控制台输出。

(编辑:上饶站长网)

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

    热点阅读