定制Banner
1、在src/main/resources下新建一个banner.txt
2、http://patorjk.com/software/taag 将网站生成的字符,复制到banner.txt中
3、再次启动项目
application.properties配置文件
设置项目的默认访问路径
server.port=8002 server.context-path=/spring-boot
此时访问的路径改为127.0.0.1:8002/spring-boot
使用XML配置
1、xml文件配置
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd
http://www.springframework.org/schema/rabbit
http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd">
<context:component-scan base-package="com.kingdee.domains"></context:component-scan>
</beans>
2、加载xml配置
package com.kingdee;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;
@SpringBootApplication
@ImportResource({"classpath:application-beans.xml"})
public class App {
public static void main(String[] args){
SpringApplication.run(App.class);
}
}
@ImportResource作为加载的注解
常规属性配置
1、设置配置文件参数
mongo.host=10.19.46.161
2、加载属性文件
package com.kingdee;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
@Component
@PropertySource(value={"classpath:common.properties"})
public class MongoConfig {
@Value("${mongo.host}")
private String host;
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
}
@PropertyResource注解加载properties属性文件
类型安全的配置
@ConfigurationProperties可以批量添加属性,不需要使用@Value逐个添加属性,可以添加前缀,然后其属性就会按照变量的名称默认在 application.* 中寻找指定的变量。如同setter方法设置属性一样。
1、配置文件参数
mongo.host=10.19.46.161 redis.host=10.19.46.162 redis.port=6379
2、加载配置文件
package com.kingdee;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "redis",locations = {"classpath:common.properties"})
public class RedisConfig {
private String host;
private String port;
}
Profile配置
在开发系统是有正式环境和测试环境,两个环境的配置参数不同,需要通过两个配置文件控制。application-prod.properties用于正式环境,application-dev.properties用于测试环境。配置文件的选择通过全局Profile控制。
主要通过application.properties中的spring.profiles.active属性进行控制
1、application.properties的配置文件
spring.profiles.active=dev
2、application-prod.properties配置文件
server.port=8002 server.context-path=/spring-boot
3、application-dev.properties配置文件
server.port=8003 server.context-path=/spring-boot