SpringBoot入门(1)——建立springBoot项目

建立基本SpringBoot项目

开发工具:IDEAjava

因为本文仅做为我的学习记录,不作过多说明,多以截图web

工程建好后主要有这么几个文件:spring

com/example/demo1/Demo1Application.java(应用启动类)tomcat

com.example.demo1.Demo1ApplicationTests(测试文件)springboot

application.properties(配置文件)app

pom.xml:Maven文件ide

到这里,一个springboot就建好了。工具

测试以下:学习

在Demo1Application中建一个rest接口开发工具

启动springboot:

tomcat8080端口启动,web页面输入http://localhost:8080/查看以下

 

配置文件解析(application.properties)

这里加了两个测试字段

 

在使用的地方加上@Value注解,如图

结果以下:

这里发现乱码,缘由为idea默认打配置文件是GBK格式

解决方法以下:

从新编辑application文件,运行后效果以下:

 

ConfigurationProperties映射bean对象解析

 

在使用的地方调用以下:

 

若是以为全部的配置都要配到application.properties麻烦,能够使用PropertySource

@PropertySource("classpath:test/test1.properties")

 

文件结构以下:

 

修改tomcat端口

相关文章
相关标签/搜索