SpringBoot 非web项目简单架构

时间:2019-07-04
本文章向大家介绍SpringBoot 非web项目简单架构,主要包括SpringBoot 非web项目简单架构使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

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!

 

$flag 上一页 下一页