Skip to content

Instantly share code, notes, and snippets.

@vikasontech
vikasontech / Application.java
Created April 19, 2017 09:15
Spring Boot Application Configuration File
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@vikasontech
vikasontech / SchedulerConfig.java
Last active April 19, 2017 10:01
Scheduler Configuration
@Configuration
@EnableScheduling
public class AppConfig {
}
@vikasontech
vikasontech / ScheduleTask.java
Created April 19, 2017 10:03
Schedule for Fix Delay
@Scheduled(fixedDelay=5000)
public void doSomething() {
// something that should execute periodically
}
@vikasontech
vikasontech / ScheduleTask.java
Created April 19, 2017 10:04
Schedule for Fix Rate
@Scheduled(fixedRate=5000)
public void doSomething() {
// something that should execute periodically
}
@vikasontech
vikasontech / ScheduleTask.java
Created April 19, 2017 10:07
Schedule with Initial Delay and Fix Rate
@Scheduled(initialDelay=1000, fixedRate=5000)
public void doSomething() {
// something that should execute periodically
}
@vikasontech
vikasontech / ScheduleTask.java
Created April 19, 2017 10:09
Schedule with cron expression
@Scheduled(cron="*/5 * * * * MON-FRI")
public void doSomething() {
// something that should execute on weekdays only
}
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>
@vikasontech
vikasontech / User.java
Last active April 26, 2017 03:39
User Entity
@Entity
public class User implements Serializable {
@Id
@Column(name = "id", nullable = false, updatable = false)
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(name = "name")
private String name;
@vikasontech
vikasontech / UserRepository.java
Created April 25, 2017 08:29
UserRepository spring jpa data repository
import com.example.entity.User;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface UserRepository extends CrudRepository<User, Long> {
}
@vikasontech
vikasontech / UserController.java
Created April 25, 2017 15:31
User Controller
package com.example.controller;
import com.example.entity.User;
import com.example.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.websocket.server.PathParam;