This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
## Spring Boot Modules
|
||||
|
||||
This module contains various modules of Spring Boot
|
||||
@@ -32,6 +32,7 @@
|
||||
<module>spring-boot-crud</module>
|
||||
<module>spring-boot-data</module>
|
||||
<module>spring-boot-environment</module>
|
||||
<module>spring-boot-exceptions</module>
|
||||
<module>spring-boot-flowable</module>
|
||||
<!-- <module>spring-boot-gradle</module> --> <!-- Not a maven project -->
|
||||
<module>spring-boot-jasypt</module>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
## Spring Boot
|
||||
|
||||
This module contains articles about Spring Boot Exceptions
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [The BeanDefinitionOverrideException in Spring Boot](https://www.baeldung.com/spring-boot-bean-definition-override-exception)
|
||||
@@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>spring-boot-exceptions</artifactId>
|
||||
<name>spring-boot-exceptions</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Demo project for working with Spring Boot exceptions</description>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>2.2.3.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>spring-boot-exceptions</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<configuration>
|
||||
<delimiters>
|
||||
<delimiter>@</delimiter>
|
||||
</delimiters>
|
||||
<useDefaultDelimiters>false</useDefaultDelimiters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>autoconfiguration</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*IntTest.java</exclude>
|
||||
</excludes>
|
||||
<includes>
|
||||
<include>**/AutoconfigurationTest.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<test.mime>json</test.mime>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<properties>
|
||||
<!-- The main class to start by executing java -jar -->
|
||||
<start-class>com.baeldung.intro.App</start-class>
|
||||
</properties>
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
<configuration>
|
||||
<include resource="/org/springframework/boot/logging/logback/base.xml"/>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<root level="error">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
<logger name="com.baeldung.testloglevel" level="debug"/>
|
||||
</configuration>
|
||||
@@ -43,6 +43,12 @@
|
||||
<artifactId>httpcore</artifactId>
|
||||
<version>${httpcore.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<version>${configuration-processor.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
@@ -121,6 +127,7 @@
|
||||
<guava.version>20.0</guava.version>
|
||||
<httpcore.version>4.4.11</httpcore.version>
|
||||
<resource.delimiter>@</resource.delimiter>
|
||||
<configuration-processor.version>2.2.4.RELEASE</configuration-processor.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.baeldung.configuration.processor;
|
||||
|
||||
import org.springframework.boot.context.properties.*;
|
||||
import org.springframework.context.annotation.*;
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "com.baeldung")
|
||||
public class CustomProperties {
|
||||
|
||||
/**
|
||||
* The url to connect to.
|
||||
*/
|
||||
String url;
|
||||
|
||||
/**
|
||||
* The time to wait for the connection.
|
||||
*/
|
||||
private int timeoutInMilliSeconds = 1000;
|
||||
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public int getTimeoutInMilliSeconds() {
|
||||
return timeoutInMilliSeconds;
|
||||
}
|
||||
|
||||
public void setTimeoutInMilliSeconds(int timeoutInMilliSeconds) {
|
||||
this.timeoutInMilliSeconds = timeoutInMilliSeconds;
|
||||
}
|
||||
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.configuration.processor;
|
||||
|
||||
import org.springframework.boot.*;
|
||||
import org.springframework.boot.autoconfigure.*;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DemoApplication.class, args);
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.configuration.processor;
|
||||
|
||||
import org.springframework.beans.factory.annotation.*;
|
||||
import org.springframework.stereotype.*;
|
||||
|
||||
@Component
|
||||
public class PropertyBeanInjection {
|
||||
|
||||
private final CustomProperties customProperties;
|
||||
|
||||
PropertyBeanInjection(@Autowired CustomProperties customProperties) {
|
||||
this.customProperties = customProperties;
|
||||
}
|
||||
|
||||
String getUrl() {
|
||||
return customProperties.getUrl();
|
||||
}
|
||||
|
||||
int getTimeoutInMilliseconds() {
|
||||
return customProperties.getTimeoutInMilliSeconds();
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.configuration.processor;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.junit.runner.*;
|
||||
import org.springframework.beans.factory.annotation.*;
|
||||
import org.springframework.boot.test.context.*;
|
||||
import org.springframework.test.context.*;
|
||||
import org.springframework.test.context.junit4.*;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@TestPropertySource("/configuration-processor.properties")
|
||||
@SpringBootTest(classes = DemoApplication.class)
|
||||
class PropertyBeanInjectionUnitTest {
|
||||
|
||||
@Autowired
|
||||
private PropertyBeanInjection propertyBeanInjection;
|
||||
|
||||
@Test
|
||||
void checkThatCustomPropertiesHaveTheCorrectValueFromPropertiesFile() {
|
||||
Assertions.assertEquals("www.abc.test.com", propertyBeanInjection.getUrl());
|
||||
Assertions.assertEquals(2000, propertyBeanInjection.getTimeoutInMilliseconds());
|
||||
}
|
||||
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
com.baeldung.url=www.abc.test.com
|
||||
com.baeldung.timeout-in-milli-seconds=2000
|
||||
@@ -1,3 +0,0 @@
|
||||
### Relevant Articles:
|
||||
|
||||
- [How to Disable Console Logging in Spring Boot](https://www.baeldung.com/spring-boot-disable-console-logging)
|
||||
@@ -17,8 +17,8 @@
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<!-- <spring-boot.version>2.1.9.RELEASE</spring-boot.version>-->
|
||||
<java.version>1.8</java.version>
|
||||
<springdoc.version>1.2.32</springdoc.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -26,6 +26,14 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -36,24 +44,13 @@
|
||||
<!-- SpringDoc -->
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-core</artifactId>
|
||||
<version>1.1.49</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>io.github.classgraph</groupId>
|
||||
<artifactId>classgraph</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<artifactId>springdoc-openapi-ui</artifactId>
|
||||
<version>${springdoc.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-ui</artifactId>
|
||||
<version>1.1.49</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.classgraph</groupId>
|
||||
<artifactId>classgraph</artifactId>
|
||||
<version>4.8.44</version>
|
||||
<artifactId>springdoc-openapi-data-rest</artifactId>
|
||||
<version>${springdoc.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
+7
@@ -6,6 +6,8 @@ import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -41,6 +43,11 @@ public class BookController {
|
||||
return repository.getBooks();
|
||||
}
|
||||
|
||||
@GetMapping("/filter")
|
||||
public Page<Book> filterBooks(Pageable pageable) {
|
||||
return repository.getBooks(pageable);
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public Book updateBook(@PathVariable("id") final String id, @RequestBody final Book book) {
|
||||
|
||||
+14
-6
@@ -1,13 +1,14 @@
|
||||
package com.baeldung.springdoc.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.baeldung.springdoc.model.Book;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.baeldung.springdoc.model.Book;
|
||||
import java.util.*;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
@Repository
|
||||
public class BookRepository {
|
||||
@@ -25,4 +26,11 @@ public class BookRepository {
|
||||
public Collection<Book> getBooks() {
|
||||
return books.values();
|
||||
}
|
||||
|
||||
public Page<Book> getBooks(Pageable pageable) {
|
||||
int toSkip = pageable.getPageSize() * pageable.getPageNumber();
|
||||
List<Book> result = books.values().stream().skip(toSkip).limit(pageable.getPageSize()).collect(toList());
|
||||
|
||||
return new PageImpl<>(result, pageable, books.size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,3 +3,6 @@ springdoc.swagger-ui.path=/swagger-ui-custom.html
|
||||
|
||||
# custom path for api docs
|
||||
springdoc.api-docs.path=/api-docs
|
||||
|
||||
# H2 Related Configurations
|
||||
spring.datasource.url=jdbc:h2:mem:springdoc
|
||||
@@ -31,4 +31,3 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
- [Spring Shutdown Callbacks](https://www.baeldung.com/spring-shutdown-callbacks)
|
||||
- [Container Configuration in Spring Boot 2](https://www.baeldung.com/embeddedservletcontainercustomizer-configurableembeddedservletcontainer-spring-boot)
|
||||
- [Validation in Spring Boot](https://www.baeldung.com/spring-boot-bean-validation)
|
||||
- [The BeanDefinitionOverrideException in Spring Boot](https://www.baeldung.com/spring-boot-bean-definition-override-exception)
|
||||
|
||||
Reference in New Issue
Block a user