码迷,mamicode.com
首页 > 编程语言 > 详细

springboot

时间:2020-02-29 00:55:23      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:src   vat   配置   xxx   click   closed   class   test   技术   

 

注解


 

  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

标签:src   vat   配置   xxx   click   closed   class   test   技术   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!