Eclipse
Spring Boot
修改Spring Boot默认的一些配置,比如:Spring Boot 内嵌的tomcat端口是8080,如果要改为8888,在application.properties写入server.port=8888Spring 默认配置进入DispatcherServlet的路径是'/',也就是拦截所有请求要修改为*.do,在application.properties写入server.servlet-path=*.doSpring Boot有一个单独的文件声明这些配置:https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
配置随机数,使用随机数#32位随机数 uuidtest.uuid=${random.value} #随机整数 test.number=${random.int} #指定范围随机数 test.limitnumber=${random.int[0,9]}test.long=${random.long}在代码中使用:@Value(value='${test.uuid}') private String uuid; @Value(value='${test.number}') private int randomID; @Value(value='${test.limitnumber}') private int limitnumber; 当然这些属性需要放到被@Service,@Controller等注解修饰的类中
占位符,使用application.properties配置文件中先前定义的值test.name=tomcattest.desc=${test.name} 是一个web容器注意:这里读取的中文有可能乱码(要分清是读到程序中乱码,还是返回到web页面乱码,我这里是第一种情况)解决:在eclipse中安装Properties Editor插件,http://propedit.sourceforge.jp/eclipse/updates/,这是地址至于这种方法为什么管用,我也不知道,也请知道的同学可以指点一下
配合@ConfigurationProperties使用,为spring bean属性添加默认值
多环境配置,使用spring.profiles.active属性如下图:如果spring.profiles.active=pro,则ProfileTest类型的bean不生成且tomcat的端口是8000