走进Spring Boot世界

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 四个核心:StarterautoconfigurationactuatorCL

  Starter  可以轻松使用需要的组件

  actuatorspring boot提供的对应用系统的自省和监控的集成功能,可以对应用系统进行配置查看、相关功能统计等。

 

                                                                                                                                                  参考Park老师笔记。

 

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值