3.SpringBoot-properties配置

来源:互联网 发布:jquery.history.js 编辑:程序博客网 时间:2024/05/17 06:38

一.自动配置内容

更多请查看:http://docs.spring.io/spring-boot/docs/1.2.3.RELEASE/reference/html/common-application-properties.html

1.mysql数据库配置

如果你设置spring.datasource.driverClassName=com.mysql.jdbc.Driver,然后这个类就会被自动加载。

DataSource配置通过外部配置文件的spring.datasource.*属性控制。

实例:

spring.datasource.url=jdbc:mysql://localhost/test

spring.datasource.username=dbuser

spring.datasource.password=dbpass

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

其他可选的配置可以查看DataSourceProperties。

2.redis配置

实例:

spring.redis.port=6379

spring.redis.database=0


spring.redis.host=

spring.redis.password=

spring.redis.timeout=2000

3.设置生效的profie(多环境配置)

spring.profiles.active=production

server.port=80

4.设置随机数

#随机字符串com.bluecoffee.random.str=${random.value}

#随机intcom.bluecoffee.random.number=${random.int}

#随机longcom.bluecoffee.random.bigNumber=${random.long}

#10以内的随机数com.bluecoffee.random.test1=${random.int(10)}

5.属性注入

com.bluecoffee.space.title=‘题目’


@Value("${com.bluecoffee.space.title}") privateStringblogTitle;