diff --git a/spring-security-rest-full/src/main/java/org/baeldung/persistence/service/impl/FooService.java b/spring-security-rest-full/src/main/java/org/baeldung/persistence/service/impl/FooService.java index c449cde8e2..533c0f5082 100644 --- a/spring-security-rest-full/src/main/java/org/baeldung/persistence/service/impl/FooService.java +++ b/spring-security-rest-full/src/main/java/org/baeldung/persistence/service/impl/FooService.java @@ -16,7 +16,7 @@ import com.google.common.collect.Lists; @Service @Transactional -public class FooService extends AbstractServiceimplements IFooService { +public class FooService extends AbstractService implements IFooService { @Autowired private IFooDao dao; diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/metric/ActuatorMetricService.java b/spring-security-rest-full/src/main/java/org/baeldung/web/metric/ActuatorMetricService.java index d0ed765c68..fec03d1ddb 100644 --- a/spring-security-rest-full/src/main/java/org/baeldung/web/metric/ActuatorMetricService.java +++ b/spring-security-rest-full/src/main/java/org/baeldung/web/metric/ActuatorMetricService.java @@ -27,7 +27,6 @@ public class ActuatorMetricService implements IActuatorMetricService { statusList = new ArrayList(); } - @Override public Object[][] getGraphData() { final Date current = new Date(); diff --git a/spring-security-rest/src/main/java/org/baeldung/persistence/model/Foo.java b/spring-security-rest/src/main/java/org/baeldung/persistence/model/Foo.java index 4fe925a7be..1941e2aa51 100644 --- a/spring-security-rest/src/main/java/org/baeldung/persistence/model/Foo.java +++ b/spring-security-rest/src/main/java/org/baeldung/persistence/model/Foo.java @@ -4,7 +4,6 @@ import java.io.Serializable; import javax.validation.constraints.Size; - public class Foo implements Serializable { private long id; diff --git a/spring-security-rest/src/main/java/org/baeldung/spring/SwaggerConfig.java b/spring-security-rest/src/main/java/org/baeldung/spring/SwaggerConfig.java index 64f61055f2..00ccb36666 100644 --- a/spring-security-rest/src/main/java/org/baeldung/spring/SwaggerConfig.java +++ b/spring-security-rest/src/main/java/org/baeldung/spring/SwaggerConfig.java @@ -19,35 +19,13 @@ import static com.google.common.collect.Lists.newArrayList; public class SwaggerConfig { @Bean - public Docket api(){ - return new Docket(DocumentationType.SWAGGER_2) - .select() - .apis(RequestHandlerSelectors.basePackage("org.baeldung.web.controller")) - .paths(PathSelectors.ant("/foos/*")) - .build() - .apiInfo(apiInfo()) - .useDefaultResponseMessages(false) - .globalResponseMessage(RequestMethod.GET, - newArrayList(new ResponseMessageBuilder() - .code(500) - .message("500 message") - .responseModel(new ModelRef("Error")) - .build(), - new ResponseMessageBuilder() - .code(403) - .message("Forbidden!!!!!") - .build())); + public Docket api() { + return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.basePackage("org.baeldung.web.controller")).paths(PathSelectors.ant("/foos/*")).build().apiInfo(apiInfo()).useDefaultResponseMessages(false) + .globalResponseMessage(RequestMethod.GET, newArrayList(new ResponseMessageBuilder().code(500).message("500 message").responseModel(new ModelRef("Error")).build(), new ResponseMessageBuilder().code(403).message("Forbidden!!!!!").build())); } private ApiInfo apiInfo() { - ApiInfo apiInfo = new ApiInfo( - "My REST API", - "Some custom description of API.", - "API TOS", - "Terms of service", - "myeaddress@company.com", - "License of API", - "API license URL"); + ApiInfo apiInfo = new ApiInfo("My REST API", "Some custom description of API.", "API TOS", "Terms of service", "myeaddress@company.com", "License of API", "API license URL"); return apiInfo; } } diff --git a/spring-security-rest/src/main/java/org/baeldung/spring/WebConfig.java b/spring-security-rest/src/main/java/org/baeldung/spring/WebConfig.java index 2de58c4e15..064fd9afa9 100644 --- a/spring-security-rest/src/main/java/org/baeldung/spring/WebConfig.java +++ b/spring-security-rest/src/main/java/org/baeldung/spring/WebConfig.java @@ -21,11 +21,9 @@ public class WebConfig extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(final ResourceHandlerRegistry registry) { - registry.addResourceHandler("swagger-ui.html") - .addResourceLocations("classpath:/META-INF/resources/"); + registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); - registry.addResourceHandler("/webjars/**") - .addResourceLocations("classpath:/META-INF/resources/webjars/"); + registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); } @Bean diff --git a/spring-security-rest/src/main/java/org/baeldung/web/ApiError.java b/spring-security-rest/src/main/java/org/baeldung/web/ApiError.java index 8352ca4ccd..e1c58da64a 100644 --- a/spring-security-rest/src/main/java/org/baeldung/web/ApiError.java +++ b/spring-security-rest/src/main/java/org/baeldung/web/ApiError.java @@ -48,6 +48,7 @@ public class ApiError { public void setMessage(final String message) { this.message = message; } + public List getErrors() { return errors; } diff --git a/spring-security-rest/src/main/java/org/baeldung/web/CustomRestExceptionHandler.java b/spring-security-rest/src/main/java/org/baeldung/web/CustomRestExceptionHandler.java index 36ad2c16ff..71b1a4775e 100644 --- a/spring-security-rest/src/main/java/org/baeldung/web/CustomRestExceptionHandler.java +++ b/spring-security-rest/src/main/java/org/baeldung/web/CustomRestExceptionHandler.java @@ -100,7 +100,6 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity(apiError, new HttpHeaders(), apiError.getStatus()); } - @ExceptionHandler({ ConstraintViolationException.class }) public ResponseEntity handleConstraintViolation(final ConstraintViolationException ex, final WebRequest request) { logger.info(ex.getClass().getName()); @@ -156,7 +155,6 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler { return new ResponseEntity(apiError, new HttpHeaders(), apiError.getStatus()); } - // 500 @ExceptionHandler({ Exception.class }) @@ -169,4 +167,3 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler { } } - diff --git a/spring-security-rest/src/test/java/org/baeldung/web/FooLiveTest.java b/spring-security-rest/src/test/java/org/baeldung/web/FooLiveTest.java index 121b308407..6e03300483 100644 --- a/spring-security-rest/src/test/java/org/baeldung/web/FooLiveTest.java +++ b/spring-security-rest/src/test/java/org/baeldung/web/FooLiveTest.java @@ -34,8 +34,6 @@ public class FooLiveTest { assertTrue(error.getErrors().get(0).contains("should be of type")); } - - @Test public void whenNoHandlerForHttpRequest_thenNotFound() { final Response response = givenAuth().delete(URL_PREFIX + "/api/xx"); diff --git a/spring-security-rest/src/test/java/org/baeldung/web/TestConfig.java b/spring-security-rest/src/test/java/org/baeldung/web/TestConfig.java index 9ee3df73f1..8b55841508 100644 --- a/spring-security-rest/src/test/java/org/baeldung/web/TestConfig.java +++ b/spring-security-rest/src/test/java/org/baeldung/web/TestConfig.java @@ -7,5 +7,4 @@ import org.springframework.context.annotation.Configuration; @ComponentScan({ "org.baeldung.web" }) public class TestConfig { - } \ No newline at end of file