栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringBoot精讲笔记

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringBoot精讲笔记

1、概览: 属性绑定,热部署,源码导入,自动配置,数据源,mp,web组件,MVC,模版,redis,消息,docker,jenkins, SpringCloud.

2、比较权威的springBoot介绍:

 

 

 3、环境要求:Spring Boot Reference documentation

 4、热部署:

ctrl+shift+alt+/      compaire.autoMake.

 

 配置文件放置位置4个。   file./config >  file.   > config/  >  ./

5、核心特色:

    1:SpringBootAppliction   自定义bannner ,K8s状态Application Availability State
    @SpringBootApplication
    public class MyApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(MyApplication.class, args);
        }
    
    }

    2、外部化配置

    spring:
      application:
        name: "myapp"
      config:
        import: "optional:file:./dev.properties"
    
    
    spring:
      config:
        import: "file:/etc/config/myconfig[.yaml]"
    
    
    k8s:
    etc/
      config/
        myapp/
          username
          password
    
    
    app:
      name: "MyApp"
      description: "${app.name} is a Spring Boot application"
    
    my:
      secret: "${random.value}"
      number: "${random.int}"
      bignumber: "${random.long}"
      uuid: "${random.uuid}"
      number-less-than-ten: "${random.int(10)}"
      number-in-range: "${random.int[1024,65536]}"

    3、@Profile("production")      

    4、任务执行和调度
              
      spring:
        task:
          execution:
            pool:
              max-size: 16
              queue-capacity: 100
              keep-alive: "10s"
      
      
      spring:
        task:
          scheduling:
            thread-name-prefix: "scheduling-"
            pool:
              size: 2

      5、Test:

      @SpringBootTest
      @AutoConfigureMockMvc
      class MyMockMvcTests {
      
          @Test
          void testWithMockMvc(@Autowired MockMvc mvc) throws Exception {
              mvc.perform(get("/")).andExpect(status().isOk()).andExpect(content().string("Hello World"));
          }
      
          // If Spring WebFlux is on the classpath, you can drive MVC tests with a WebTestClient
          @Test
          void testWithWebTestClient(@Autowired WebTestClient webClient) {
              webClient
                      .get().uri("/")
                      .exchange()
                      .expectStatus().isOk()
                      .expectBody(String.class).isEqualTo("Hello World");
          }
      
      }
      
      
      class MyTests {
      
          private TestRestTemplate template = new TestRestTemplate();
      
          @Test
          void testRequest() throws Exception {
              ResponseEntity headers = this.template.getForEntity("https://myhost.example.com/example", String.class);
              assertThat(headers.getHeaders().getLocation()).hasHost("other.example.com");
          }
      
      }

      5、Web

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/770395.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号