Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Search | Email

5.3. application.properties

配置资源文件位置,默认application.properties是放在jar包中的,通过spring.config.location可以制定外部配置文件,这样更便于运维。

java -jar demo.jar --spring.config.location=/opt/config/application.properties
		

5.3.1. PID FILE

spring.pid.fail-on-write-error= # Fail if ApplicationPidFileWriter is used but it cannot write the PID file.
spring.pid.file= # Location of the PID file to write (if ApplicationPidFileWriter is used).
			

5.3.2. 内嵌 tomcat server

5.3.2.1. server

server.port=8080 	# 监听端口
server.address= 	# 绑定的地址
server.context-path= #默认为/
				

连接数配置

server.tomcat.max-threads=2048 # 最大线程数
				

5.3.2.2. tomcat

如果前端有 nginx 代理这个配置可以禁用

server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.directory=/tmp/logs
server.tomcat.accesslog.pattern=common
server.tomcat.accesslog.prefix=www.netkiller.cn.access
server.tomcat.accesslog.suffix=.log
				

5.3.2.3. logging

logging.path=/tmp # 日志目录默认为 /tmp
logging.file=your.log # 日志文件名称,默认为spring.log
				
java -jar spring-boot-app.jar --logging.file=/tmp/spring-boot-app.log				
				

5.3.2.4. charset

Spring boot 默认并非UTF-8 所以下面配置必设,否则将会出现

spring.messages.encoding=UTF-8
server.tomcat.uri-encoding=UTF-8
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
				

5.3.2.5. Session 配置

server.session-timeout= #session有效时长
server.session.cookie.name=PHPSESSID
server.session.cookie.domain=.example.com
server.session.cookie.http-only=true
server.session.cookie.path=/
				

5.3.2.6. error 路径

server.error.path=/error				
				

5.3.2.7. 压缩传输

server.compression.enabled=true			#是否开启压缩,默认为false.
server.compression.excluded-user-agents	#指定不压缩的user-agent,多个以逗号分隔,默认值为:text/html,text/xml,text/plain,text/css
server.compression.mime-types			#指定要压缩的MIME type,多个以逗号分隔.
server.compression.min-response-size	#执行压缩的阈值,默认为2048
				

5.3.2.8. ssl

生成证书

server.ssl.* #ssl相关配置

keytool -genkey -alias springboot -keyalg RSA -keystore /www/ssl/spring
设置密码 123456			
				

配置 application.properties

server.ssl.enabled 启动tomcat ssl配置
server.ssl.keyAlias 别名
server.ssl.keyPassword 密码
server.ssl.keyStore 位置			
				
server.port=8443
server.ssl.enabled=true
server.ssl.keyAlias=springboot
server.ssl.keyPassword=123456
server.ssl.keyStore=/www/ssl/spring
				

5.3.3. JSON

# Pretty-print JSON responses
spring.jackson.serialization.indent_output=true
			

5.3.4. SMTP 相关配置

spring.mail.host=smtp.netkiller.cn
#spring.mail.username=
#spring.mail.password=
#spring.mail.properties.mail.smtp.auth=true
#spring.mail.properties.mail.smtp.starttls.enable=true
#spring.mail.properties.mail.smtp.starttls.required=true		
mail.smtp.debug=true
			

5.3.5. Redis

# REDIS (RedisProperties)
# Redis数据库索引(默认为0)
spring.redis.database=0
# Redis服务器地址
spring.redis.host=localhost
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码(默认为空)
spring.redis.password=
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.pool.max-active=8
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.pool.max-wait=-1
# 连接池中的最大空闲连接
spring.redis.pool.max-idle=8
# 连接池中的最小空闲连接
spring.redis.pool.min-idle=0
# 连接超时时间(毫秒)
spring.redis.timeout=0
			

5.3.6. MongoDB

格式:mongodb://用户名:密码@主机地址/数据库

spring.data.mongodb.uri=mongodb://user:passw0rd@mdb.netkiller.cn/test
spring.data.mongodb.repositories.enabled=true
			

5.3.7. MySQL

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://主机地址:端口号/数据库
spring.datasource.username=用户名
spring.datasource.password=密码
spring.jpa.database=MYSQL	# 启用JPA支持	
			

5.3.8. Oracle

spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@//odb.netkiller.cn:1521/orcl
spring.datasource.username=orcl
spring.datasource.password=passw0rd
spring.datasource.connection-test-query="SELECT 1 FROM DUAL"
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect

spring.jpa.show-sql=true
#spring.jpa.hibernate.ddl-auto=none
#spring.jpa.hibernate.ddl-auto=create-drop
spring.datasource.max-active=50
spring.datasource.initial-size=5
spring.datasource.max-idle=10
spring.datasource.min-idle=5
spring.datasource.test-while-idle=true
spring.datasource.test-on-borrow=false
spring.datasource.validation-query=SELECT 1 FROM DUAL
spring.datasource.time-between-eviction-runs-millis=5000
spring.datasource.min-evictable-idle-time-millis=60000
			

5.3.9. velocity

spring.velocity.resourceLoaderPath=classpath:/templates/
spring.velocity.prefix=
spring.velocity.suffix=.vm
spring.velocity.cache=false
spring.velocity.check-template-location=true
spring.velocity.content-type=text/html
spring.velocity.charset=UTF-8
spring.velocity.properties.input.encoding=UTF-8
spring.velocity.properties.output.encoding=UTF-8