走进Spring Boot世界
来源:互联网 发布:自动生成迷宫算法 编辑:程序博客网 时间:2024/05/29 03:35
1.快速创建项目:
通过网站 start.spring.io 一键生成项目,速度快。
2.定制化启动图案:
定制化图案连接:http://patorjk.com/software/taag
在resource目录创建banner.txt。将图案复制在txt中。
3.注解
@RestController是@Controller和@ResponseBody的结合体,两个标注合并起来的作用。
@component (把普通pojo实例化到spring容器中,相当于配置文件中的<bean id="" class=""/>)
@ConfigurationProperties根据类型校验和管理application中的bean。
@SpringBootApplication注解,它包括三个注解:
@Configuration:表示将该类作用springboot配置文件类。
@EnableAutoConfiguration:表示程序启动时,自动加载springboot默认的配置。
@ComponentScan:表示程序启动是,自动扫描当前包及子包下所有类。
4.启动项目
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
5.Controller类
@RestController
public class DemoApplication2 {
@Autowired
StudentConstants studentConstants;
@RequestMapping(value="/",method=RequestMethod.GET)
public String index(){
return studentConstants.getName()+studentConstants.getAge();
}
}
6.实体
@Component
@ConfigurationProperties(prefix="dn.student")
public class StudentConstants {
private String name;
private String age;
省略get,set
}
7.Spring boot 的配置文件
Application.properties 或者 application.yml
Application.properties 内容:
server.port=80
server.context-path=/demo
logging.level.org.springframework.web=DEBUG
#spring.profiles.active=product
spring.profiles.active=dev 设置开发模式(spring.profiles.active=#对应 application-#.properties)
8.application-product.properties内容:
dn.student.name=maoxu product
dn.student.age= 22
9.application-dev.properties内容:
dn.student.name=maoxu dev
dn.student.age= 22
10.Spring boot 核心
Spring boot 四个核心:Starter,autoconfiguration,actuator,CL
Starter 可以轻松使用需要的组件
actuator是spring boot提供的对应用系统的自省和监控的集成功能,可以对应用系统进行配置查看、相关功能统计等。
- 走进Spring Boot世界
- 陆续走进JAVA世界
- 走进程序世界
- 走进CSDN世界
- 走进博客的世界
- 走进汇编的世界
- 走进ReactiveCocoa的世界
- 走进Git的世界
- 走进递归的世界
- 走进 Redis 的世界
- 走进 Redis 的世界
- 走进 Redis 的世界
- 走进 Redis 的世界
- 走进 Redis 的世界
- 走进 Redis 的世界
- 走进 Redis 的世界
- 走进 Redis 的世界
- 走进Karel的世界
- 机器学习最常用优化之一——梯度下降优化算法综述
- HTTPS 性能优化
- golang以插件的方式加载golang动态库
- 关于lhgdialog二级弹窗问题
- Android图片压缩参数Bitmap.Config.RGB_565,Bitmap.Config.ARGB_8888等
- 走进Spring Boot世界
- Kotlin-30.相等性(Equality)
- 数据结构 C语言 双向链栈 迷宫问题
- go拾遗--使用竞争检测器标志来编译程序
- linux安装mysql后修改密码
- python学习(字符串转换)
- 24.职责链模式
- c++类模板的声明与定义
- 考试题/(ㄒoㄒ)/~~