springboot的基本使用(一)
2018-01-26 17:55
246 查看
1.springboot项目的简单搭建
http://blog.csdn.net/qq_37730579/article/details/79065388点击打开链接
2.springboot的配置文件
springboot使用一个全局配置文件 文件名为 application.properties 或者是application.yml 放置在 src/main/resources目录或者类路径的/config下
springboot全局配置文件的作用:对默认配置进行修改 如:对Tomcat端口的修改 server.port=8081 等
全局配置信息:
http://blog.csdn.net/qq_37730579/article/details/79066049点击打开链接
3.配置文件的读取
将配置文件放在 src/main/resources的resource目录中
user.properties的文件内容为:
配置文件类:
读取配置文件的内容:
@Value("${user.username}")
private String username;
或者使用类型安全的配置 :
将user.properties 中的内容封装为一个实体对象 如:User类
读取方式:
乱码问题的解决:
在application.properties中配置
banner.charset=UTF-8
server.tomcat.uri-encoding=UTF-8
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
spring.messages.encoding=UTF-8
如果还是不能解决问题 还需要在eclipse中配置:
http://www.cnblogs.com/zdz8207/p/java-eclipse-properties.html点击打开链接
4.Profile配置
Profile是spring用来针对不同的配置提供支持,全局Profile配置使用application-(profile).properties (application-prod.properties)
通过在application.properties中设置spring.profiles.active = prod 类指定活动的Profile
5.eclipse中VM arguments 的配置和读取
配置:
读取:
System.getProperty("server.port")
http://blog.csdn.net/qq_37730579/article/details/79065388点击打开链接
2.springboot的配置文件
springboot使用一个全局配置文件 文件名为 application.properties 或者是application.yml 放置在 src/main/resources目录或者类路径的/config下
springboot全局配置文件的作用:对默认配置进行修改 如:对Tomcat端口的修改 server.port=8081 等
全局配置信息:
http://blog.csdn.net/qq_37730579/article/details/79066049点击打开链接
3.配置文件的读取
将配置文件放在 src/main/resources的resource目录中
user.properties的文件内容为:
配置文件类:
读取配置文件的内容:
@Value("${user.username}")
private String username;
或者使用类型安全的配置 :
将user.properties 中的内容封装为一个实体对象 如:User类
读取方式:
乱码问题的解决:
在application.properties中配置
banner.charset=UTF-8
server.tomcat.uri-encoding=UTF-8
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
spring.messages.encoding=UTF-8
如果还是不能解决问题 还需要在eclipse中配置:
http://www.cnblogs.com/zdz8207/p/java-eclipse-properties.html点击打开链接
4.Profile配置
Profile是spring用来针对不同的配置提供支持,全局Profile配置使用application-(profile).properties (application-prod.properties)
通过在application.properties中设置spring.profiles.active = prod 类指定活动的Profile
5.eclipse中VM arguments 的配置和读取
配置:
读取:
System.getProperty("server.port")
相关文章推荐
- Springboot使用RedisTemplate基本步骤
- 【Java】SpringBoot入门学习及基本使用
- SpringBoot: jpa基本使用
- springboot基本使用笔记----添加jsp支持及打包部署
- springboot基本使用笔记----添加socket服务及获取spring bean
- springboot基本使用笔记----静态资源(js ,css ...)路径
- SpringBoot系列三:SpringBoot基本概念(统一父 pom 管理、SpringBoot 代码测试、启动注解分析、配置访问路径、使用内置对象、项目打包发布)
- oracle11g安装和基本的使用,手把手看图教你用起来。
- PHP的session与cookie的基本使用介绍
- Linux之 linux7防火墙基本使用及详解
- FireBug的基本使用
- Python3.6 字符串的基本使用
- SwipeRefreshLayout基本使用和冲突解决机制
- Spring2.5中使用方法注入(method inject)之基本方法替代(basis method replacement)
- Linux笔记(2)_vi/vim 基本使用方法
- linux下GNU、G++编辑器的安装及基本使用
- python re正则表达式基本使用介绍
- vuex基本使用心得(1)
- Scrapy爬虫入门教程 安装和基本使用