全局配置文件|学习笔记

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

开发者学堂课程【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 的全局配置文件

相关文章
|
人工智能 网络安全 数据安全/隐私保护
操作系统的演进:从命令行到图形用户界面
本文将带领读者穿越时光隧道,探索操作系统的发展历程。我们将从最早的命令行界面(CLI)开始,逐步走向现代的图形用户界面(GUI)。通过这篇文章,你将了解到操作系统如何适应技术变革,满足用户需求,以及它们是如何塑造我们今天数字生活的。让我们一起解锁操作系统的历史密码,发现那些改变了世界的创新故事。
|
运维 C# UED
C# 一分钟浅谈:异常处理的最佳实践
【9月更文挑战第5天】在软件开发中,异常处理对保证程序稳定性和用户体验至关重要。本文从基础概念入手,详细讲解C#中的异常处理策略,并通过代码示例说明如何有效实现异常管理。文章涵盖`try`、`catch`和`finally`块的使用,探讨常见问题如忽略异常和过度捕获,并提出最佳实践建议,如使用具体异常类型、记录异常信息及优雅地处理异常,助力开发者构建更健壮的应用程序。
725 1
|
Java 定位技术
Threejs路径规划案例V1
这篇文章详细介绍了使用Three.js进行三维路径规划的实现方法,包括设置三维场景、实现车辆避障以及展示规划路径等内容。
344 1
|
搜索推荐 安全 Windows
Windows10系统 无法更换锁屏图片一直转圈圈(含替换系统默认锁屏壁纸教程)异常处理
Windows10系统 无法更换锁屏图片一直转圈圈(含替换系统默认锁屏壁纸教程)异常处理
2528 0
Windows10系统 无法更换锁屏图片一直转圈圈(含替换系统默认锁屏壁纸教程)异常处理
Typora 使用技巧2 -- 强制换行,修改表格列宽
Typora 使用技巧2 -- 强制换行,修改表格列宽
1878 0
|
存储 搜索推荐 Android开发
一键网页视频提取神器!!!
一键网页视频提取神器!!!
|
Android开发
java.net.SocketException: Permission denied 连网权限
引用:http://zhidao.baidu.com/question/169346890.html 这是一个经典错误, Socket不能对外连接,错误不会被报出,调试的时候,能看到Exception, 一般是抛出 java.net.socketexception permission denied这个异常。
2265 0
|
机器学习/深度学习 算法 PyTorch
【13】变分自编码器(VAE)的原理介绍与pytorch实现
【13】变分自编码器(VAE)的原理介绍与pytorch实现
3405 0
【13】变分自编码器(VAE)的原理介绍与pytorch实现
|
负载均衡 算法 Java
Spring Cloud 之 Ribbon
Spring Cloud 之 Ribbon
618 0
|
算法 Java 数据安全/隐私保护
加密解决方案-Java实现RSA非对称加密
本文基于RSA加密算法原理,详述什么是RSA算法、RSA加密解密原理进行实践的过程。
1210 1
加密解决方案-Java实现RSA非对称加密