Muhammet Can TONBUL Muhammet Can TONBUL - 2 months ago 7
JSON Question

Spring boot Request Mapping with Schedule

I'm newbie on spring boot. I'm already implement some request mappings with successfully output in json.


ad: "Windows 10",
mimari: "amd64",
versiyon: "10.0",
diskSize: 918,
freediskSize: 614,
cores: 8,
usablediskSize: 614

And My Controller here

public class GreetingController {

@RequestMapping(value = "/gJson", produces=MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody MyPojo gJson(){

And now, I need ... example when I'm going to this link >
getting json from
but every "X" seconds.

Thanks For Helping.


How is /GetInfo being served? Is it just a standard HTML page? If so you can code a Javascript element that has a setInterval() to make an XMLHttpRequest to the /gJson endpoint. There are a number of other ways to do it depending on what libraries you want to use to have browser to server communications.

* Update * Sample project:

Main aspect that allows the refresh is the HTML page at src/main/resources/static/GetInfo.html

<!DOCTYPE html>
<meta charset="ISO-8859-1">

<script type="text/javascript">
    $(function() {
        window.setInterval(function() {
                url : "/gJson"
            }).done(function(data, status, jqXHR) {
        }, 10000);

The controller is straightforward as outlined in the question.

public class GreetingController {
    @GetMapping(value = "/gJson", produces = MediaType.APPLICATION_JSON_VALUE)
    public MyPojo gJson() {
        return new MyPojo("Windows 10", System.currentTimeMillis());

Finally the MyPojo is just a simple two field class.

public class MyPojo {
    private String ad;
    private long timestamp;

    public MyPojo(String ad, long timestamp) { = ad;
        this.timestamp = timestamp;

    public String getAd() {
        return ad;

    public void setAd(String ad) { = ad;

    public long getTimestamp() {
        return timestamp;

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;

I included the timestamp so that you can see the time refreshing every 10 seconds on the web page.