Skip to content

Commit 9b1820f

Browse files
authored
Merge branch 'master' into snyk-upgrade-8e029a02ea69b96353571fa0b1d4011e
2 parents ce37972 + e813058 commit 9b1820f

5 files changed

Lines changed: 56 additions & 25 deletions

File tree

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,3 @@ target/
2828
build/
2929
!**/src/main/**/build/
3030
!**/src/test/**/build/
31-
32-
### VS Code ###
33-
.vscode/

.vscode/launch.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"configurations": [
3+
{
4+
"type": "java",
5+
"name": "Spring Boot (Debug)",
6+
"request": "launch",
7+
"cwd": "${workspaceFolder}",
8+
"console": "internalConsole",
9+
"mainClass": "ar.com.nanotaboada.java.samples.spring.boot.Application",
10+
"projectName": "java.samples.spring.boot",
11+
"args": "--spring.profiles.active=local"
12+
}
13+
]
14+
}

pom.xml

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
<properties>
2020
<java.version>21</java.version>
2121
</properties>
22-
<!--
22+
<!--
2323
Dependencies
2424
________________________________________________________________________________
2525
-->
2626
<dependencies>
27-
<!--
27+
<!--
2828
Spring Boot Starter Web
2929
Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat
3030
as the default embedded container.
@@ -36,7 +36,7 @@
3636
<artifactId>spring-boot-starter-web</artifactId>
3737
<version>3.3.1</version>
3838
</dependency>
39-
<!--
39+
<!--
4040
Spring Boot Starter Data JPA
4141
Starter for using Spring Data JPA with Hibernate
4242
@@ -47,7 +47,7 @@
4747
<artifactId>spring-boot-starter-data-jpa</artifactId>
4848
<version>3.3.1</version>
4949
</dependency>
50-
<!--
50+
<!--
5151
H2 Database Engine
5252
Provides a fast in-memory database that supports JDBC API and R2DBC access, with a small
5353
(2mb) footprint. Supports embedded and server modes as well as a browser based console
@@ -72,25 +72,25 @@
7272
<artifactId>spring-boot-starter-validation</artifactId>
7373
<version>3.3.0</version>
7474
</dependency>
75-
<!--
75+
<!--
7676
ModelMapper
7777
Simple, Intelligent, Object Mapping.
7878
79-
https://mvnrepository.com/artifact/org.modelmapper/modelmapper
79+
https://mvnrepository.com/artifact/org.modelmapper/modelmapper
8080
-->
8181
<dependency>
8282
<groupId>org.modelmapper</groupId>
8383
<artifactId>modelmapper</artifactId>
8484
<version>3.2.0</version>
8585
</dependency>
8686

87-
<!--
87+
<!--
8888
Spring Boot Starter Security
8989
Starter for using Spring Security.
90-
90+
9191
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security
9292
-->
93-
<!--
93+
<!--
9494
<dependency>
9595
<groupId>org.springframework.boot</groupId>
9696
<artifactId>spring-boot-starter-security</artifactId>
@@ -99,17 +99,17 @@
9999
<!--
100100
Spring Security Test
101101
Spring Security
102-
103-
https://mvnrepository.com/artifact/org.springframework.security/spring-security-test
102+
103+
https://mvnrepository.com/artifact/org.springframework.security/spring-security-test
104104
-->
105-
<!--
105+
<!--
106106
<dependency>
107107
<groupId>org.springframework.security</groupId>
108108
<artifactId>spring-security-test</artifactId>
109109
<scope>test</scope>
110110
</dependency>
111111
-->
112-
<!--
112+
<!--
113113
Spring Boot Starter Test
114114
Starter for testing Spring Boot applications with libraries including JUnit Jupiter,
115115
Hamcrest and Mockito.
@@ -122,7 +122,7 @@
122122
<version>3.2.3</version>
123123
<scope>test</scope>
124124
</dependency>
125-
<!--
125+
<!--
126126
AssertJ Fluent Assertions
127127
Rich and fluent assertions for testing for Java
128128
@@ -144,22 +144,22 @@
144144
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
145145
<version>2.6.0</version>
146146
</dependency>
147-
<!--
147+
<!--
148148
Spring Boot Starter Actuator
149149
Starter for using Spring Boot's Actuator which provides production ready features to
150150
help you monitor and manage your application
151151
152-
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator
152+
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator
153153
-->
154154
<dependency>
155155
<groupId>org.springframework.boot</groupId>
156156
<artifactId>spring-boot-starter-actuator</artifactId>
157157
<version>3.3.0</version>
158158
</dependency>
159-
<!--
160-
CVE-2022-1471
159+
<!--
160+
CVE-2022-1471
161161
-->
162-
<!--
162+
<!--
163163
SnakeYAML
164164
YAML 1.1 parser and emitter for Java
165165
@@ -170,9 +170,20 @@
170170
<artifactId>snakeyaml</artifactId>
171171
<version>2.2</version>
172172
</dependency>
173+
<!--
174+
Spring Boot Starter Cache
175+
Starter for using Spring Framework's caching support
176+
177+
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-cache
178+
-->
179+
<dependency>
180+
<groupId>org.springframework.boot</groupId>
181+
<artifactId>spring-boot-starter-cache</artifactId>
182+
<version>3.3.1</version>
183+
</dependency>
173184
</dependencies>
174185
<build>
175-
<!--
186+
<!--
176187
Plugins
177188
________________________________________________________________________________
178189
-->
@@ -181,7 +192,7 @@
181192
<groupId>org.springframework.boot</groupId>
182193
<artifactId>spring-boot-maven-plugin</artifactId>
183194
</plugin>
184-
<!--
195+
<!--
185196
JaCoCo :: Maven Plugin
186197
The JaCoCo Maven Plugin provides the JaCoCo runtime agent to your tests and allows
187198
basic report creation.

src/main/java/ar/com/nanotaboada/java/samples/spring/boot/Application.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.springframework.boot.CommandLineRunner;
77
import org.springframework.boot.SpringApplication;
88
import org.springframework.boot.autoconfigure.SpringBootApplication;
9+
import org.springframework.cache.annotation.EnableCaching;
910
import org.springframework.context.annotation.Bean;
1011

1112
import ar.com.nanotaboada.java.samples.spring.boot.models.Book;
@@ -17,6 +18,7 @@
1718
* and component scanning.
1819
* */
1920
@SpringBootApplication
21+
@EnableCaching
2022
public class Application {
2123

2224
private final BooksRepository repository;
@@ -43,4 +45,4 @@ CommandLineRunner seed() {
4345
public static void main(String[] args) {
4446
SpringApplication.run(Application.class, args);
4547
}
46-
}
48+
}

src/main/java/ar/com/nanotaboada/java/samples/spring/boot/services/BooksService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import jakarta.validation.Validator;
44

55
import org.modelmapper.ModelMapper;
6+
import org.springframework.cache.annotation.CacheEvict;
7+
import org.springframework.cache.annotation.CachePut;
8+
import org.springframework.cache.annotation.Cacheable;
69
import org.springframework.stereotype.Service;
710

811
import ar.com.nanotaboada.java.samples.spring.boot.models.Book;
@@ -26,6 +29,7 @@ public BooksService(BooksRepository repository, Validator validator, ModelMapper
2629
* Create
2730
* ----------------------------------------------------------------------------------------- */
2831

32+
@CachePut(value = "books", key = "#bookDTO.isbn")
2933
public boolean create(BookDTO bookDTO) {
3034
boolean created = false;
3135
Book book = mapper.map(bookDTO, Book.class);
@@ -40,6 +44,7 @@ public boolean create(BookDTO bookDTO) {
4044
* Retrieve
4145
* ----------------------------------------------------------------------------------------- */
4246

47+
@Cacheable(value = "books", key = "#isbn")
4348
public BookDTO retrieveByIsbn(String isbn) {
4449
BookDTO bookDTO = null;
4550
Book book = repository.findByIsbn(isbn).orElse(null);
@@ -53,6 +58,7 @@ public BookDTO retrieveByIsbn(String isbn) {
5358
* Update
5459
* ----------------------------------------------------------------------------------------- */
5560

61+
@CachePut(value = "books", key = "#bookDTO.isbn")
5662
public boolean update(BookDTO bookDTO) {
5763
boolean updated = false;
5864
Book book = mapper.map(bookDTO, Book.class);
@@ -67,6 +73,7 @@ public boolean update(BookDTO bookDTO) {
6773
* Delete
6874
* ----------------------------------------------------------------------------------------- */
6975

76+
@CacheEvict(value = "books", key = "#isbn")
7077
public boolean delete(String isbn) {
7178
boolean deleted = false;
7279
if (!isbn.isBlank() && repository.existsById(isbn)) {

0 commit comments

Comments
 (0)