spring4倾向于基于注解的配置,强化的注解的功能,对比与spring3还是有很多的区别;spring boot对spring的各个组件功能管理,基于默认配置即可简单构建一个spring4的项目,对于小项目是一个比较好的选择,本篇基于java8 gradle的spring boot 1.3版本整理。

基础的gradle配置:

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.1.RELEASE")
}
} apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot' jar {
baseName = 'gs-scheduling-tasks'
version = '0.1.0'
} repositories {
mavenCentral()
} sourceCompatibility = 1.8
targetCompatibility = 1.8 dependencies {
compile("org.springframework.boot:spring-boot-starter-web") testCompile("org.springframework.boot:spring-boot-starter-test")
} task "create-dirs" << {
sourceSets*.java.srcDirs*.each { it.mkdirs() }
sourceSets*.resources.srcDirs*.each { it.mkdirs() }
sourceSets*.webapp.srcDirs*.each { it.mkdirs() }
}

 建立如下结果目录

Application.java

 package com.spring4.hello;

 import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; /**
* @author ff
* @Date 15-12-18.
* @Discreption
*/
@SpringBootApplication
public class Application { public static void main(String[] args) {
SpringApplication.run(Application.class, args);
} }

这样一个简单的项目便建立好了。

1.数据库模块(jpa)

添加对应的gradle配置

    compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("mysql:mysql-connector-java")

spring boot会默认读取根目录下application.properties属性文件,可以将数据库配置放入其中

spring.datasource.url=jdbc:mysql://localhost:3306/test?characterEncoding=utf-8&useUnicode=true
spring.datasource.username=root
spring.datasource.password=123456 spring.jpa.show-sql=true
#spring.jpa.hibernate.ddl-auto=create

2.计划任务模块

添加配置注解@EnableScheduling即可

package com.spring4.hello.task;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import java.time.LocalTime; /**
* @author ff
* @Date 15-12-21.
* @Discreption
*/
@Component
public class ScheduledTasks { @Scheduled(fixedRate = 1000)
public void sayCurrentTime() {
LocalTime now = LocalTime.now();
System.out.println("Current Time="+now);
} }

spring boot了解的更多相关文章

  1. 玩转spring boot——快速开始

    开发环境: IED环境:Eclipse JDK版本:1.8 maven版本:3.3.9 一.创建一个spring boot的mcv web应用程序 打开Eclipse,新建Maven项目 选择quic ...

  2. 【微框架】之一:从零开始,轻松搞定SpringCloud微框架系列--开山篇(spring boot 小demo)

    Spring顶级框架有众多,那么接下的篇幅,我将重点讲解SpringCloud微框架的实现 Spring 顶级项目,包含众多,我们重点学习一下,SpringCloud项目以及SpringBoot项目 ...

  3. 玩转spring boot——开篇

    很久没写博客了,而这一转眼就是7年.这段时间并不是我没学习东西,而是园友们的技术提高的非常快,这反而让我不知道该写些什么.我做程序已经有十几年之久了,可以说是彻彻底底的“程序老炮”,至于技术怎么样?我 ...

  4. 玩转spring boot——结合redis

    一.准备工作 下载redis的windows版zip包:https://github.com/MSOpenTech/redis/releases 运行redis-server.exe程序 出现黑色窗口 ...

  5. 玩转spring boot——AOP与表单验证

    AOP在大多数的情况下的应用场景是:日志和验证.至于AOP的理论知识我就不做赘述.而AOP的通知类型有好几种,今天的例子我只选一个有代表意义的“环绕通知”来演示. 一.AOP入门 修改“pom.xml ...

  6. 玩转spring boot——结合JPA入门

    参考官方例子:https://spring.io/guides/gs/accessing-data-jpa/ 接着上篇内容 一.小试牛刀 创建maven项目后,修改pom.xml文件 <proj ...

  7. 玩转spring boot——结合JPA事务

    接着上篇 一.准备工作 修改pom.xml文件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&q ...

  8. 玩转spring boot——结合AngularJs和JDBC

    参考官方例子:http://spring.io/guides/gs/relational-data-access/ 一.项目准备 在建立mysql数据库后新建表“t_order” ; -- ----- ...

  9. 玩转spring boot——结合jQuery和AngularJs

    在上篇的基础上 准备工作: 修改pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&q ...

  10. 玩转spring boot——MVC应用

    如何快速搭建一个MCV程序? 参照spring官方例子:https://spring.io/guides/gs/serving-web-content/ 一.spring mvc结合thymeleaf ...

随机推荐

  1. SPSS时间序列分析

    时间序列分析必须建立在预处理的基础上…… 今天看了一条新闻体会到了网络日志的重要性…… 指数平滑法(Exponential Smoothing,ES)是布朗(Robert G..Brown)所提出,布 ...

  2. poj Organize Your Train part II

    http://poj.org/problem?id=3007 #include<cstdio> #include<algorithm> #include<cstring& ...

  3. Windows提供了两种将DLL映像到进程地址空间的方法(隐式和显式)

    调用DLL,首先需要将DLL文件映像到用户进程的地址空间中,然后才能进行函数调用,这个函数和进程内部一般函数的调用方法相同.Windows提供了两种将DLL映像到进程地址空间的方法: 1. 隐式的加载 ...

  4. VS中的预先生成事件和后期生成事件

    原文:VS中的预先生成事件和后期生成事件 在C#开发中,有时候需要在程序编译之前或之后做一些操作. 要达到这个目的,可以使用Visual Studio中的预先生成事件和后期生成事件. 下图是一个简单例 ...

  5. HDOJ(HDU) 1976 Software Version(简单判断)

    Problem Description 相信大家一定有过在网上下载软件而碰到多个不同版本的情况. 一般来说,软件的版本号由三个部分组成,主版本号(Major Version Number),子版本号( ...

  6. vim 插件

    自动补全插件更换:youcompleteme github:https://github.com/Valloric/YouCompleteMe

  7. POJ1661 Help Jimmy

    Help Jimmy Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9863 Accepted: 3201 Descriptio ...

  8. html5 教程

    http://www.tutorialspoint.com/html5/index.htm

  9. Git常用命令清单

    创建 在指定目录创建工作仓库,未指定时在当前目录 git init [dir] 创建不包含工作区的仓库 git init --bare 克隆远程仓库到本地 git clone url 配置 git c ...

  10. Andrdoid中相应用程序的行为拦截实现方式之----从Java层进行拦截

    致谢: 感谢 简行之旅的这篇blog:http://blog.csdn.net/l173864930/article/details/38455951,这篇文章是參考这篇blog的进行一步一步操作的, ...