zoukankan      html  css  js  c++  java
  • Java框架spring Boot学习笔记(一):开始第一个项目

    新建一个项目,选择Spring initializr

    修改group和项目名

    添加依赖包Web,MongoDB

    设置保存位置和工程名

    新建一个test的文件

    输入代码:

     1 package com.xxx.test.spider;
     2 
     3 import org.springframework.stereotype.Service;
     4 
     5 import javax.annotation.PostConstruct;
     6 import java.util.Date;
     7 
     8 import static java.lang.Thread.*;
     9 
    10 //如果一个类带了@Service注解,将自动注册到Spring容器
    11 @Service
    12 public class test {
    13     //启动spring时运行这个方法
    14     @PostConstruct
    15     public void fun(){
    16         while (true){
    17             try {
    18                 Thread.sleep(1000); //每隔1秒
    19             } catch (InterruptedException e) {
    20                 e.printStackTrace();
    21             }
    22             System.out.println(new Date()); //打印当前时间
    23         }
    24     }
    25 }

    运行输出:

      .   ____          _            __ _ _
     /\ / ___'_ __ _ _(_)_ __  __ _    
    ( ( )\___ | '_ | '_| | '_ / _` |    
     \/  ___)| |_)| | | | | || (_| |  ) ) ) )
      '  |____| .__|_| |_|_| |_\__, | / / / /
     =========|_|==============|___/=/_/_/_/
     :: Spring Boot ::        (v1.5.8.RELEASE)
    
    2017-10-30 15:33:23.583  INFO 8108 --- [           main] com.xxx.test.TestApplication             : Starting TestApplication on CXYF-100-049 with PID 8108 (D:IdeaProjectsx	est	argetclasses started by jacky.jiang in D:IdeaProjectsx	est)
    2017-10-30 15:33:23.585  INFO 8108 --- [           main] com.xxx.test.TestApplication             : No active profile set, falling back to default profiles: default
    2017-10-30 15:33:23.621  INFO 8108 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@6dde5c8c: startup date [Mon Oct 30 15:33:23 CST 2017]; root of context hierarchy
    Mon Oct 30 15:33:24 CST 2017
    Mon Oct 30 15:33:25 CST 2017
    Mon Oct 30 15:33:26 CST 2017
  • 相关阅读:
    将字符串数组转换成整形数组
    层的三级联动
    sql
    工作中的感悟
    asp.net如何抓取其他网站的内容
    看不到的SQl
    对数据库中时间为空的处理和数据转换成百分数
    不带查询条件的分页
    svn中出现红色感叹号
    视图的创建(根据已有的表)
  • 原文地址:https://www.cnblogs.com/zylq-blog/p/7754759.html
Copyright © 2011-2022 走看看