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

SpringBoot 非web项目简单架构

时间:2019-07-05 00:39:26      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:toc   line   service   info   alt   cto   udt   resource   stat   

1.截图

技术图片

2.DemoService

package com.github.weiwei02.springcloudtaskdemo;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
    public class DemoService {

    @Value("${test.value}")
    private String testValueAnno;

    public void test(){
        System.out.println(testValueAnno);
    }
}

3.SpringCloudTaskDemoApplication

package com.github.weiwei02.springcloudtaskdemo;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.Resource;

@SpringBootApplication
public class SpringCloudTaskDemoApplication  implements CommandLineRunner {

    @Resource
    private DemoService demoService;

    public static void main(String[] args) throws Exception {

        SpringApplication.run(SpringCloudTaskDemoApplication.class, args);

    }

    public void run(String... strings){
        new Thread(){
            public void run() {
                try {
                    Thread.sleep(10000);
                    demoService.test();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

        }
        }.start();
    }

}

4.application.yml

spring:
  application:
    name: HelloWorld
logging:
  level.org.springframework.cloud.task: DEBUG

test:
  value: I am Chinese!

 

SpringBoot 非web项目简单架构

标签:toc   line   service   info   alt   cto   udt   resource   stat   

原文地址:https://www.cnblogs.com/bierenbiewo11/p/11135460.html

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