zoukankan      html  css  js  c++  java
  • Spring Boot学习——Spring Boot配置文件application

            Spring Boot配置文件有两种格式: application.properties 和 application.yml。两种配置文件只需要使用一个。

            这两种配置文件的语法有些区别,如下

                    1. application.properties

                            server.port = 8080         -- tomcat 端口

                            server.context-path = /webName    -- URL路径

                    2. application.yml

                            server:

                                    port: 8080         -- tomcat 端口,注意冒号后面有空格

                                    context-path: /webName    -- URL路径,注意冒号后面有空格

            一、Java类中使用配置

                    1. 方法一

    @value("${server.port}")
    private String port;

                    2. 方法二

    @Compoent
    @ConfigurationProperties(prefix="server")
    public class ServerProperties{
          private String port;
          private String context-path;
          
          // set/get方法      
    }

        注意:使用注解 @Compoent是为了方便在其他类中使用@Autowired引用该类

            二、分环境使用配置文件

                    再创建两个配置文件 application-dev.yml(测试环境配置文件) 和 application-prod.yml(正式环境配置文件)

                    在 application.yml 中配置如下:

    spring:
        profiles:
            active: dev

                    注: 上面的配置是使用配置文件application-dev.yml,改成 active:prod即可使用配置文件application-prod.yml

            三、java命令启动使用配置

                    java -jar ****.jar --spring.profiles.active=dev

                    注:上面的配置是使用配置文件application-dev.yml,改成 --spring.profiles.active=prod即可使用配置文件application-prod.yml

  • 相关阅读:
    Openstack API 开发 快速入门
    virtualBox虚拟机到vmware虚拟机转换
    使用Blogilo 发布博客到cnblogs
    Openstack Troubleshooting
    hdoj 1051 Wooden Sticks(上升子序列个数问题)
    sdut 2430 pillars (dp)
    hdoj 1058 Humble Numbers(dp)
    uva 10815 Andy's First Dictionary(快排、字符串)
    sdut 2317 Homogeneous squares
    hdoj 1025 Constructing Roads In JGShining's Kingdom(最长上升子序列+二分)
  • 原文地址:https://www.cnblogs.com/aston/p/7237039.html
Copyright © 2011-2022 走看看