新建一个项目,选择Spring initializr

修改group和项目名

添加依赖包Web,MongoDB

设置保存位置和工程名

新建一个test的文件

输入代码:

 package com.xxx.test.spider;

 import org.springframework.stereotype.Service;

 import javax.annotation.PostConstruct;
import java.util.Date; import static java.lang.Thread.*; //如果一个类带了@Service注解,将自动注册到Spring容器
@Service
public class test {
//启动spring时运行这个方法
@PostConstruct
public void fun(){
while (true){
try {
Thread.sleep(1000); //每隔1秒
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(new Date()); //打印当前时间
}
}
}

运行输出:

  .   ____          _            __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: 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:\IdeaProjects\x\test\target\classes started by jacky.jiang in D:\IdeaProjects\x\test)
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

Java框架spring Boot学习笔记(一):开始第一个项目的更多相关文章

  1. Java框架spring Boot学习笔记(六):Spring Boot事务管理

    SpringBoot和Java框架spring 学习笔记(十九):事务管理(注解管理)所讲的类似,使用@Transactional注解便可以轻松实现事务管理.

  2. Java框架spring Boot学习笔记(三):Controller的使用

    Controller注解介绍 @Controller:处理http请求 @RestController: Spirng4之后新加的注解,其实是一个组合注解等同于@ResponseBody和@Contr ...

  3. Java框架spring Boot学习笔记(二):Hello Spring Boot、以及项目属性配置

    新建一个新建一个SpringBootTest工程 新建一个HelloController.java文件 package com.example.demo; import org.springframe ...

  4. Java框架spring Boot学习笔记(五):Spring Boot操作MySQL数据库增、删、改、查

    在pom.xml添加一下代码,添加操作MySQL的依赖jar包. <dependency> <groupId>org.springframework.boot</grou ...

  5. Java框架spring Boot学习笔记(四):Spring Boot操作MySQL数据库

    在pom.xml添加一下代码,添加操作MySQL的依赖jar包. <dependency> <groupId>org.springframework.boot</grou ...

  6. Java框架spring Boot学习笔记(十):传递数据到html页面的例子

    新建一个templates文件夹和index.html <!DOCTYPE html> <html> <head lang="en"> < ...

  7. Java框架spring Boot学习笔记(七):@Configuration,@bean注解

    @Configuration作用在类上,相当于一个xml文件 @bean作用于方法上,相当于xml配置中的<bean>标签 一个例子: 新建一个Springboot工程 新建一个User类 ...

  8. Java框架spring Boot学习笔记(九):一个简单的RESTful API

    RESTful API设计需求如下: User.java package com.springboot.test; public class User { private Long id; priva ...

  9. Java框架spring Boot学习笔记(八):@PropertySource,@Value注解

    获取配置文件 忽略配置文件不存在时报错

随机推荐

  1. 微信小程序 | 多个按钮或VIEW,切换状态的简单方法(三元)

    wxml文件 wxss文件 js文件

  2. Jquery仿百度经验左右滚动切换效果(转)

    http://www.xwcms.net/webAnnexImages/fileAnnex/201608/61342/index.html

  3. 15.python并发编程(线程--进程--协程)

    一.进程:1.定义:进程最小的资源单位,本质就是一个程序在一个数据集上的一次动态执行(运行)的过程2.组成:进程一般由程序,数据集,进程控制三部分组成:(1)程序:用来描述进程要完成哪些功能以及如何完 ...

  4. python第三方模块的导入

    模块搜索路径 当我们尝试加载一个模块时,Python会在指定的路径下搜索对应的.py文件,如果找不到,就会报错: >>> import module1 Traceback (most ...

  5. MySQL 和 Oracle 在 MyBatis 使用中的区别

    MySQL 和 Oracle 在 MyBatis 使用中的区别: 区别 MySQL Oracle 存储过程的参数模式 mode 为 IN 时,是否需要指定 jdbcType 不需要:MyBatis 为 ...

  6. Illegalmixofcollations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT)foroperation '= 连表查询排序规则问题

    两张 表 关联 ,如果 join的字段 排序规则 不一样就会出这个问题 . 解决办法 ,统一 排序规则. 在说说区别,utf8mb4_general_ci 更加快,但是在遇到某些特殊语言或者字符集,排 ...

  7. xterm下字体设置

    code ~/.Xdefaults xterm*locale: true xterm.utf8: true xterm*utf8Title: true ! 滚动条 !XTerm*scrollBar: ...

  8. PCL中Sample_consensus分割支持的几何模型

    随机采样一致分割法,从点云中分割出线.面等几何元素 #include <pcl/sample_consensus/method_types.h> #include <pcl/samp ...

  9. 在WINDOWS7下无U盘安装WINDOWS10

    第一步:下载cn_windows_10_business_editions_version_1803_updated_march_2018_x64_dvd_12063730.iso 第二步:解压里面的 ...

  10. js基础系列之【作用域】

    声明:形成本文的出发点仅仅是个人总结记录,避免遗忘,并非详实的教程:文中引用了经过个人加工的其它作者的内容,并非原创.学海无涯 什么是作用域? 作用域就是一套规则,用于确定在何处以及如何查找变量(标识 ...