<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
Spring Boot能從多種屬性源得到屬性【按照優先級排序】java
application.properties和application.yml文件能放在如下四個位置【按照優先級排序】mysql
- 禁用模板緩存
- 配置嵌入式服務器
server: port: 8443 ssl: key-store: file:///path/to/mykeys.jks key-store-password: letmein key-password: letmein
配置日誌web
logging: path: /var/logs/ file: BookWorm.log level: root: WARN org: springframework: security: DEBUG 默認狀況下,日誌文件的大小達到10MB時會切分一次。
經過logging.config屬性指定自定義的名字: logging: config: classpath:logging-config.xml
配置數據源spring
spring: datasource: url: jdbc:mysql://localhost/readinglist username: dbuser password: dbpass driver-class-name: com.mysql.jdbc.Driver
應用程序 Bean 的配置外置sql
@ConfigurationProperties(prefix="amazon")
amazon: associateId: habuma-20
,@ConfigurationProperties註解不會生效,除 非先向Spring配置類添加@EnableConfigurationProperties註解。但一般無需這麼 作,由於Spring Boot自動配置後面的所有配置類都已經加上了@EnableConfigurationProperties註解。
amazon.associateId = amazon.associate_id = amazon.associate-id
使用 Profile 進行配置apache
spring: profiles: active: production logging: level: root: INFO --- spring: profiles: development logging: level: root: DEBUG --- spring: profiles: production logging: path: /tmp/ file: BookWorm.log level: root: WARN 使用一組三個連字符(---)做爲分隔符
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <!--目前1.4.2版本支持--> <version>1.4.2.RELEASE</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> <resources> <resource> <!-- 指定resources插件處理哪一個目錄下的資源文件 --> <directory>src/main/webapp</directory> <!--注意這次必需要放在此目錄下才能被訪問到--> <targetPath>META-INF/resources</targetPath> <includes> <include>**/**</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/**</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/java</directory> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> </resources> </build>