Merge pull request #4191 from eugenp/spring-boot-2-upgrade

replace requestmapping, update properties
This commit is contained in:
Loredana Crusoveanu 2018-05-08 22:03:39 +03:00 committed by GitHub
commit dc32c9dce0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 43 additions and 52 deletions

View File

@ -1,4 +1,2 @@
server.port=9090
spring.jpa.show-sql=true spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto = update spring.jpa.hibernate.ddl-auto = update

View File

@ -20,7 +20,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Dynamic DTO Validation Config Retrieved from DB](http://www.baeldung.com/spring-dynamic-dto-validation) - [Dynamic DTO Validation Config Retrieved from DB](http://www.baeldung.com/spring-dynamic-dto-validation)
- [Custom Information in Spring Boot Info Endpoint](http://www.baeldung.com/spring-boot-info-actuator-custom) - [Custom Information in Spring Boot Info Endpoint](http://www.baeldung.com/spring-boot-info-actuator-custom)
- [Using @JsonComponent in Spring Boot](http://www.baeldung.com/spring-boot-jsoncomponent) - [Using @JsonComponent in Spring Boot](http://www.baeldung.com/spring-boot-jsoncomponent)
- [Create a Custom Auto-Configuration with Spring Boot](http://www.baeldung.com/spring-boot-custom-auto-configuration)
- [Testing in Spring Boot](http://www.baeldung.com/spring-boot-testing) - [Testing in Spring Boot](http://www.baeldung.com/spring-boot-testing)
- [Guide to @ConfigurationProperties in Spring Boot](http://www.baeldung.com/configuration-properties-in-spring-boot) - [Guide to @ConfigurationProperties in Spring Boot](http://www.baeldung.com/configuration-properties-in-spring-boot)
- [How to Get All Spring-Managed Beans?](http://www.baeldung.com/spring-show-all-beans) - [How to Get All Spring-Managed Beans?](http://www.baeldung.com/spring-show-all-beans)

View File

@ -6,6 +6,7 @@ import java.util.UUID;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -22,7 +23,7 @@ public class UserController {
private static final Logger LOG = LoggerFactory.getLogger(UserController.class); private static final Logger LOG = LoggerFactory.getLogger(UserController.class);
@RequestMapping("") @GetMapping("")
public List<User> getAllUsers() { public List<User> getAllUsers() {
LOG.info("Fetching all the users"); LOG.info("Fetching all the users");
return Arrays.asList( return Arrays.asList(

View File

@ -4,7 +4,7 @@ import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.GetMapping;
import com.baeldung.displayallbeans.service.FooService; import com.baeldung.displayallbeans.service.FooService;
@ -13,7 +13,7 @@ public class FooController {
@Autowired @Autowired
private FooService fooService; private FooService fooService;
@RequestMapping(value = "/displayallbeans") @GetMapping(value = "/displayallbeans")
public String getHeaderAndBody(Map<String, Object> model) { public String getHeaderAndBody(Map<String, Object> model) {
model.put("header", fooService.getHeader()); model.put("header", fooService.getHeader());
model.put("message", fooService.getBody()); model.put("message", fooService.getBody());

View File

@ -3,7 +3,7 @@ package com.baeldung.errorhandling.controllers;
import org.springframework.boot.web.servlet.error.ErrorController; import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.GetMapping;
import javax.servlet.RequestDispatcher; import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -13,7 +13,7 @@ public class MyErrorController implements ErrorController {
public MyErrorController() {} public MyErrorController() {}
@RequestMapping(value = "/error") @GetMapping(value = "/error")
public String handleError(HttpServletRequest request) { public String handleError(HttpServletRequest request) {
Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);

View File

@ -1,7 +1,7 @@
package com.baeldung.git; package com.baeldung.git;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap; import java.util.HashMap;
@ -19,7 +19,7 @@ public class CommitInfoController {
@Value("${git.commit.id}") @Value("${git.commit.id}")
private String commitId; private String commitId;
@RequestMapping("/commitId") @GetMapping("/commitId")
public Map<String, String> getCommitId() { public Map<String, String> getCommitId() {
Map<String, String> result = new HashMap<>(); Map<String, String> result = new HashMap<>();
result.put("Commit message", commitMessage); result.put("Commit message", commitMessage);

View File

@ -1,17 +1,17 @@
package com.baeldung.intro.controller; package com.baeldung.intro.controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
public class HomeController { public class HomeController {
@RequestMapping("/") @GetMapping("/")
public String root() { public String root() {
return "Index Page"; return "Index Page";
} }
@RequestMapping("/local") @GetMapping("/local")
public String local() { public String local() {
return "/local"; return "/local";
} }

View File

@ -1,14 +1,14 @@
package com.baeldung.rss; package com.baeldung.rss;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller @Controller
@RequestMapping(value = "/rss", produces = "application/*") @RequestMapping(value = "/rss", produces = "application/*")
public class ArticleRssController { public class ArticleRssController {
@RequestMapping(method = RequestMethod.GET) @GetMapping
public String articleFeed() { public String articleFeed() {
return "articleFeedView"; return "articleFeedView";
} }

View File

@ -7,7 +7,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication @SpringBootApplication
@ -27,7 +27,7 @@ public class WarInitializerApplication extends SpringBootServletInitializer {
@RestController @RestController
public static class WarInitializerController { public static class WarInitializerController {
@RequestMapping("/") @GetMapping("/")
public String handler(Model model) { public String handler(Model model) {
model.addAttribute("date", LocalDateTime.now()); model.addAttribute("date", LocalDateTime.now());
return "WarInitializerApplication is up and running!"; return "WarInitializerApplication is up and running!";

View File

@ -2,12 +2,12 @@ package com.baeldung.webjar;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.GetMapping;
@Controller @Controller
public class TestController { public class TestController {
@RequestMapping(value = "/") @GetMapping(value = "/")
public String welcome(Model model) { public String welcome(Model model) {
return "index"; return "index";
} }

View File

@ -7,8 +7,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -26,18 +25,18 @@ public class GenericEntityController {
entityList.add(new GenericEntity(4l, "entity_4")); entityList.add(new GenericEntity(4l, "entity_4"));
} }
@RequestMapping("/entity/all") @GetMapping("/entity/all")
public List<GenericEntity> findAll() { public List<GenericEntity> findAll() {
return entityList; return entityList;
} }
@RequestMapping(value = "/entity", method = RequestMethod.POST) @PostMapping("/entity")
public GenericEntity addEntity(GenericEntity entity) { public GenericEntity addEntity(GenericEntity entity) {
entityList.add(entity); entityList.add(entity);
return entity; return entity;
} }
@RequestMapping("/entity/findby/{id}") @GetMapping("/entity/findby/{id}")
public GenericEntity findById(@PathVariable Long id) { public GenericEntity findById(@PathVariable Long id) {
return entityList.stream().filter(entity -> entity.getId().equals(id)).findFirst().get(); return entityList.stream().filter(entity -> entity.getId().equals(id)).findFirst().get();
} }

View File

@ -1,7 +1,7 @@
package org.baeldung.common.error; package org.baeldung.common.error;
import org.springframework.boot.web.servlet.error.ErrorController; import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.GetMapping;
public class MyCustomErrorController implements ErrorController { public class MyCustomErrorController implements ErrorController {
@ -11,7 +11,7 @@ public class MyCustomErrorController implements ErrorController {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
@RequestMapping(value = PATH) @GetMapping(value = PATH)
public String error() { public String error() {
return "Error heaven"; return "Error heaven";
} }

View File

@ -1,6 +1,6 @@
package org.baeldung.common.error.controller; package org.baeldung.common.error.controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@ -9,12 +9,12 @@ public class ErrorController {
public ErrorController() { public ErrorController() {
} }
@RequestMapping("/400") @GetMapping("/400")
String error400() { String error400() {
return "Error Code: 400 occured."; return "Error Code: 400 occured.";
} }
@RequestMapping("/errorHeaven") @GetMapping("/errorHeaven")
String errorHeaven() { String errorHeaven() {
return "You have reached the heaven of errors!!!"; return "You have reached the heaven of errors!!!";
} }

View File

@ -10,7 +10,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -23,7 +23,7 @@ public class SpringBootApplication {
private static ApplicationContext applicationContext; private static ApplicationContext applicationContext;
@RequestMapping("/") @GetMapping("/")
String home() { String home() {
return "TADA!!! You are in Spring Boot Actuator test application."; return "TADA!!! You are in Spring Boot Actuator test application.";
} }

View File

@ -1,21 +1,22 @@
server.port=9090 server.port=9090
server.contextPath=/springbootapp server.servlet.contextPath=/springbootapp
management.port=8081 management.server.port=8081
management.address=127.0.0.1 management.server.address=127.0.0.1
#debug=true #debug=true
spring.jpa.show-sql=true spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto = update spring.jpa.hibernate.ddl-auto = update
endpoints.shutdown.enabled=true
endpoints.jmx.domain=Spring Sample Application management.endpoints.jmx.domain=Spring Sample Application
endpoints.jmx.uniqueNames=true management.endpoints.jmx.uniqueNames=true
management.endpoint.shutdown.enabled=true
##jolokia.config.debug=true ##jolokia.config.debug=true
##endpoints.jolokia.enabled=true ##endpoints.jolokia.enabled=true
##endpoints.jolokia.path=jolokia ##endpoints.jolokia.path=jolokia
spring.jmx.enabled=true spring.jmx.enabled=true
endpoints.jmx.enabled=true management.endpoints.jmx.enabled=true
## for pretty printing of json when endpoints accessed over HTTP ## for pretty printing of json when endpoints accessed over HTTP
http.mappers.jsonPrettyPrint=true http.mappers.jsonPrettyPrint=true
@ -26,11 +27,7 @@ info.app.description=This is my first spring boot application G1
info.app.version=1.0.0 info.app.version=1.0.0
info.java-vendor = ${java.specification.vendor} info.java-vendor = ${java.specification.vendor}
## Spring Security Configurations
security.user.name=admin1
security.user.password=secret1
management.security.role=SUPERUSER management.security.role=SUPERUSER
management.endpoint.shutdown.enabled=true
logging.level.org.springframework=INFO logging.level.org.springframework=INFO
@ -38,15 +35,12 @@ logging.level.org.springframework=INFO
servlet.name=dispatcherExample servlet.name=dispatcherExample
servlet.mapping=/dispatcherExampleURL servlet.mapping=/dispatcherExampleURL
#banner.charset=UTF-8 #spring.banner.charset=UTF-8
#banner.location=classpath:banner.txt #spring.banner.location=classpath:banner.txt
#banner.image.location=classpath:banner.gif #spring.banner.image.location=classpath:banner.gif
#banner.image.width= //TODO #spring.banner.image.width= //TODO
#banner.image.height= //TODO #spring.banner.image.height= //TODO
#banner.image.margin= //TODO #spring.banner.image.margin= //TODO
#banner.image.invert= //TODO #spring.banner.image.invert= //TODO
contactInfoType=email contactInfoType=email
endpoints.beans.id=springbeans
endpoints.beans.sensitive=false