设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 数据 手机
当前位置: 首页 > 综合聚焦 > 编程要点 > 语言 > 正文

Spring Boot默许配置文件

发布时间:2022-07-19 11:50 所属栏目:51 来源:互联网
导读:通常情况下,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,查看控制台输出。

(编辑:ASP站长网)

    网友评论
    推荐文章
      热点阅读