Spring Boot使用一个全局的配置文件application.properties或者application.yml,配置文件放在src/main/resources目录下。
1、修改tomcat默认端口和默认访问路径
在application.properties中添加代码
server.contex-path=/helloboot ---------默认访问路径修改为http:l//localhost:8080/helloboot
server.port =8081-------------------端口号修改为8081
常规属性配置
我们在application.properties中定义属性,然后再代码中直接使用@value注入即可。
book.ruthor=罗贯中
book.name=三国
book.priyin=sanguoyanyi
类的属性中引入注解@Value(value="${book.name}")
启动程序,输入localhost:8080/hello
代码1 结果1问题:中文乱码
1、查找各种资料,均是采用了设置application.properties中各种文件编译文件的格式为UTF-8,如下
banner.charset=UTF-8server.tomcat.uri-encoding=UTF-8spring.http.encoding.charset=UTF-8spring.http.encoding.enabled=truespring.http.encoding.force=truespring.messages.encoding=UTF-8
2、对于IDEA,需要设置默认编码
file--->setting---->editor---->file encoding---->properties.files下的
Default encoding for properties files:UTF-8;后面的Transparent。。。。也要勾选。
之后我重新构建了项目,启动后,中文显示正常。
类型安全的配置
待实验
网友评论