Spring: creating a nice RESTful WebService

In this article,i described, how fast you can build a application with SpringBoot, now we add another class, which represents a RESTful WebService and gives us a JSON list of yll our users in the database.

package de.professional_webworkx.crm.web;

import java.util.List;

import javax.inject.Inject;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import de.professional_webworkx.crm.domain.User;
import de.professional_webworkx.crm.domain.interfaces.UserRepository;

@RestController
@EnableAutoConfiguration
@RequestMapping("api")
public class UserWebService {

	@Inject
	UserRepository repository;
	
	@RequestMapping("/")
	public @ResponseBody List getAllUsers() {
		List allUser = repository.findAll();
		return allUser;
	}
}

The result:

[{"id":1,"firstName":"Max","lastName":"Mustermann"},{"id":2,"firstName":"Max","lastName":"Mustermann1"},{"id":3,"firstName":"Max","lastName":"Mustermann1"},{"id":4,"firstName":"Max","lastName":"Mustermann1"},{"id":5,"firstName":"Max","lastName":"Mustermann1"},{"id":6,"firstName":"Max","lastName":"Mustermann1"}]

Have fun.