首页 > 编程语言 > 详细

springboot

时间:2020-02-29 03:56:05      阅读:52      评论:0      收藏:0      [点我收藏+]

 

注解


 

  1. @SpringBootApplication
    标注在类上,表示该类是“主配置类”,运行该类的main方法启动应用

  2. @RunWith(SpringRunner.class)
    @SpringBootTest
    使用 Spring 进行单元测试

  3. @ConfigurationProperties
    获取配置文件值
    技术分享图片
    package com.ruoyi;
    
    import org.springframework.boot.context.properties.ConfigurationProperties;
    import org.springframework.stereotype.Component;
    
    import lombok.Data;
    
    @Component
    @ConfigurationProperties(prefix = "ruoyi")
    @Data
    public class ProDemo {
    
        private String profile;
    }
    View Code
    技术分享图片
    package com.ruoyi;
    
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.test.context.junit4.SpringRunner;
    
    @RunWith(SpringRunner.class)
    @SpringBootTest
    public class TestBoot {
        
        @Autowired
        private ProDemo pro;
    
        @Test
        public void doTest() {
            System.err.println("xxx" + pro.getProfile());
        }
    }
    View Code

     
    读取配置文件,方法2:

    技术分享图片
        @Value("${ruoyi.port}")
        private Integer port;
    View Code

     

 

 

 

 

 

 

springboot

springboot

原文:https://www.cnblogs.com/argor/p/12380986.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!