全局配置文件|学习笔记

简介: 快速学习全局配置文件

开发者学堂课程【SpringBoot 实战教程 全局配置文件】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址:https://developer.aliyun.com/learning/course/651/detail/10772


全局配置文件


内容介绍

一、定义

二、举例

 

一、定义

1、springboot 会根据在 pom 中依赖的 jar 包做自动配置但是有些情况下不希望使用 springboot 的默认配置那么可以使用 springboot 全局配置文件解决这个问题

2、Spring Boot 项目使用一个全局的配置文件 application.properties 或者是 application.yml,这里需要注意全局配置文件名称必须叫 application扩展名可以是 properties 或者是 ymlyml 格式目前使用的比较多它是使用 yaml 的语言进行定义yml 语言是以数据为中心的语言具备面向对象的特征在 resources 目录下或者类路径下的 /config. 下,一般放到 resources 下。

 

二、举例

1、resources 下创建全局配置文件注意名称必须是 application首先创建 properties 文件

2、比如 springboot 下默认配置的 tomcat 端口是8080,如果不想使用8080,可以用 server.port 属性名进行改变修改 tomcat 的端口为 8088:server.port=8088

3、properties 左边是名称右边是值如果是 yml 格式呢可以进行对比注意写数值之前加空格

ServerPort8088

4、写了两个配置文件springboot 都会进行读取配置的值是一样的

5、启动可以看到端口号变成8088。

Tomcatstarted onport(s) : 8088(http)

进入 DispatcherServlet 的规则为: * .htmlserver.context- path=/hello

6、访问 springboot 工程路径默认的是/,改变默认改成 ww

Server.context-path=/ww

在 properties 文件里面都要写 server但是在 yml 格式里面直接写 context-patserver 可以省略相比较下 yml 格式简便主要加空格

context-path: /ww

7、重新启动可以看到 /ww

8、输入http://localhost:8088/访问上下文路径是 ww回车可以看到 hello world

9、如果要改变 springboot 默认配置通过全局配置文件 application 进行改变application 全局文件有两种格式

10、默认配置如下在使用时进行查找即可

# BANNER 关于 banner 的配置启动的图标

banner.charset=UTF-8 # Banner file encoding.

banner. location=classpath:banner.txt # Banner file Location.

banner. image . location=classpath:banner.gif # Banner image file

Location(jpg/png can also be used).

banner. image.width= # Width of the banner image in chars (default 76)

banner. image.height= # Height of the banner image in chars (defaultbased on image height)

banner. image. margin= # Left hand image margin in chars (default 2)

banner. image. invert= # If images should be inverted for dark terminalthemes (default false)

# LOGGING 和日志相关的配置

logging.config= # Location of thelogging configuration file. Forinstance c Lasspath: Logback. xmL for Logback

logging. exception- conversion-word=%wEx # Conversion word used whenlogging exceptions.

logging.file= # Log file name. For instance myapp. Log

logging.level.*= # LogLeveLs severity mapping. For instance

‘logging. level. org. springframework=DEBUG

logging.path= # Location of the log file. For instance‘ /var/Log’

logging. pattern.console- # Appender pattern for output to the console.

OnLy supported with the default logback setup.

logging. pattern.file= # Appender pattern for output to the file. Onlysupported with the defaultLogback setup.

logging. pattern.level= # Appender pattern for Log Level (default%5p).

OnLy supported with the default logback setup.

logging. register- shutdown-hook=false # Register a shutdown hook, forthe Logging system when it is initialized.

# AOP

spring. aop.auto=true # Add @EnabLeAspectJAutoProxy.

spring.aop. proxy-target-class=false # Whether subclass-based (CGLIB)

proxies are to be created ( true) as opposed to standard Java

interface-based proxies (false).

# IDENTITY (ContextIdApplicationContextInitializer)

spring. application. index= # AppLication index.

spring. application.name= # Application name.

# ADMIN (SpringApplicationAdminJmxAutoConfiguration)

spring. application. admin. enabled=false # Enable admin features forthe application.

spring. application. admin. jmx-name=org. springfr amework. boot: type=Admin, name=SpringApplication # JMX name of the application admin MBean.

# AUTO-CONFIGURATION

spring. autoconfigure.exclude= # Auto-configuration classes toexcLode .

# SPRING CORE

spring. beaninfo .ignore-trueネSkip search of BeanInfo cLasses.

#SPRING CACHE (cacheProperties)spring缓存

spring. cache.cache-names= Comma-seporated list of coche names tocreate if supported by the underlying cache manager.

spring. cache.caffeine.spec= # The sped to use ta create caches. Check

CaffeineSpec for more details on the spec format.

spring. cache . couchbase , expiration=0并Entry expiration in

millisecords.. By defouLt the eritries never expire.

spring. cache. ehcache.config= # The location of the configuration fileto useto initialize EhCache.

spring. cache. guava.spec= # The spec to use to create caches. CheckCacheBuilderSpec for more details on the spec format.

spring. cache. infinispan. config= # The Location of the configuration file to use to initialize Infinispan.

spring. cache.jcache. config= # The location of the configuration file to use to initialize the cache manager.

spring. cache. jcache. provider= # Fully qualified name of the CachingProvider impLementation to use to retrieve the JSR-107

compliant cache manager. OnLy needed if more than one

JSR-107

impLementation is available on the cLasspath.

spring.cache. type= # Cache type, auto-detected according to the environment by default.

# SPRING CONFIG - using environment property only

(ConfigFileApplicationListener)

spring. config.location= # Config file locations.

spring. config . name=application # Config file name.

# HAZELCAST (HazelcastProperties)

spring. hazelcast.config= # The Location of the configuration file touse to initialize Hazelcast.

# PROJECT INFORMATION (ProjectInfoProperties )

spring. info. build. location=classpath :META-INF /build- info. Properties # Location of the generated build-info.properties file.

spring. info. git .location=classpath:git. properties # Location of theenerated git. properties file.

#JMX

spring. jmx. default-domain= # JMX domain name.

spring. jmx. enabled=true # Expose management beans to the JMX domain.

spring. jmx.server=mbeanServer # MBeanServer bean name.

# Email (MailProperties)

spring. mail. default-encoding=UTF-8 # Default MimeMessage encoding.

spring. mail.host= # SMTP server host. For instance ’smtp. example. Com‘

spring. mail. jndi-name= # Session JNDI name. When set, takes precedence to others mail settings.

spring. mail.password= # Login password of the SMTP server.

spring. mail.port= # SMTP server port.

spring. mail. properties.*= # Additional JavaMail session properties.

spring. mail. prötocol=smtp # ProtocoL used by the SMTP server.

spring. mail. test- connection=false # Test that the mail server isavailable on startup .

spring. mail. username= # Login user of the SMTP server.

# APPLICATION SETTINGS (SpringApplication)

spring. main. banner- mode=console # Mode used to dispLay the banner when the appLication runs.

spring. main. sources= # Sources (cLass name, package name or XMLresource location) to include in the AppL icationContext.

spring. main. web-environment= # Run the application in a web-environment (auto-detected by default) .

# FILE ENCODING (FileEncodingApplicationL istener )

spring. mandatory-file-encoding= # Expected character encoding theappLication must use.

# INTERNATIONALIZATION (MessageSourceAutoConfiguration)

spring. messages. always-use-message-format=false # Set whether toalways apply the MessageFormat rules, parsing even messages withoutarguments.

spring. messages .basename=messages # Comma-separated List of basenames ,each following the ResourceBundle convention.

spring. messages.cache-seconds=-1 # Loaded resource bundle filescache expiration, in seconds. When set to -1, bundLes are cachedforever .

spring. messages .encoding=UTF-8 # Message bundles encoding.

spring. messages. fallback-to-system- locale=true # Set whether to fallback to the system Locale if no files for a specific Locale have beenfound.

# OUTPUT

spring. output. Ans.enabled=detect # Configure the ANSI output.

# PID FILE (ApplicationPidFileWriter)

spring. pid. fail-on-write-error= # FaiL if AppLicationPidFileWriter

# PROFILES

spring. profiles.active= # Comma-separated List (orlist if using YAML )of active profiles .

spring. profiles .include= # Unconditionally octivate the specifiedcomma separated profiles (or List of profiles if using YAML).

# SENDGRID (SendGridAutoConfiguration)

spring. sendgrid.api-key= # SendGrid api key (alternative to username/ passward)

spring, sendgrid.username= # SendGrid account username

spring. sendgrid.password= # SendGrid account pas sword

spring, sendgrid. proxy,host= # SendGrid proxy host

spr ing. sendgrid.proxy.port= # SendGrid proxy port

还有 jsp 服务器sessioncookicetomcatfreemarker 页面静态化encoding 编码jacksonspringmac 前缀后缀

spring. mvc.view.prefix= # Spring MVC view prefix.

spring. mvc.view.suffix= # Spring MVC view suffix.

还有 jabcmongoredisthymeleaf 网版引擎webservices在使用时查阅文档即可这就是 springboot 的全局配置文件

目录
打赏
0
0
0
0
55
分享
相关文章
Spring的配置文件,如何配置端口号,,properties,yml获取配置项等方法,外观模式及其优缺点,日志代表的信息
Spring的配置文件,如何配置端口号,,properties,yml获取配置项等方法,外观模式及其优缺点,日志代表的信息
|
8月前
|
【SpringBoot】工程配置文件的4级分类 —— 配置文件优先级问题
【SpringBoot】工程配置文件的4级分类 —— 配置文件优先级问题
95 0
从源码角度分析 Nacos 配置文件加载以及加载优先级
从源码角度分析 Nacos 配置文件加载以及加载优先级
803 0
零基础学小程序 —— 全局配置(四)
零基础学小程序 —— 全局配置(四)
210 0
零基础学小程序 —— 全局配置(四)
一键修改配置文件
import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.
1098 0