Skip to content

Commit 0c910b1

Browse files
committed
Added Spring boot examples
1 parent 21228b5 commit 0c910b1

File tree

82 files changed

+362
-1627
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+362
-1627
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
HELP.md
1+
readme.md
22
target/
33
!.mvn/wrapper/maven-wrapper.jar
44
!**/src/main/**/target/
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,28 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>3.1.1</version>
8+
<version>3.1.2</version>
99
<relativePath/> <!-- lookup parent from repository -->
1010
</parent>
1111
<groupId>com.stacktips</groupId>
12-
<artifactId>c003-movies-rest-api-monogdb</artifactId>
12+
<artifactId>spring-context-path</artifactId>
1313
<version>0.0.1-SNAPSHOT</version>
14-
<name>movies-api</name>
14+
<name>spring-context-path</name>
1515
<description>Demo project for Spring Boot</description>
1616
<properties>
1717
<java.version>17</java.version>
1818
</properties>
1919
<dependencies>
20-
2120
<dependency>
2221
<groupId>org.springframework.boot</groupId>
23-
<artifactId>spring-boot-starter-data-mongodb</artifactId>
22+
<artifactId>spring-boot-starter-web</artifactId>
2423
</dependency>
2524

2625
<dependency>
27-
<groupId>org.springframework.boot</groupId>
28-
<artifactId>spring-boot-starter-web</artifactId>
26+
<groupId>org.projectlombok</groupId>
27+
<artifactId>lombok</artifactId>
28+
<optional>true</optional>
2929
</dependency>
30-
3130
<dependency>
3231
<groupId>org.springframework.boot</groupId>
3332
<artifactId>spring-boot-starter-test</artifactId>
@@ -40,6 +39,14 @@
4039
<plugin>
4140
<groupId>org.springframework.boot</groupId>
4241
<artifactId>spring-boot-maven-plugin</artifactId>
42+
<configuration>
43+
<excludes>
44+
<exclude>
45+
<groupId>org.projectlombok</groupId>
46+
<artifactId>lombok</artifactId>
47+
</exclude>
48+
</excludes>
49+
</configuration>
4350
</plugin>
4451
</plugins>
4552
</build>

c001-spring-boot-rest-api/src/main/java/com/stacktips/SpringBootRestApiApplication.java renamed to YT001-setting-context-path/src/main/java/com/stacktips/ExampleApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55

66
@SpringBootApplication
7-
public class SpringBootRestApiApplication {
7+
public class ExampleApplication {
88

99
public static void main(String[] args) {
10-
SpringApplication.run(SpringBootRestApiApplication.class, args);
10+
SpringApplication.run(ExampleApplication.class, args);
1111
}
1212

1313
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.stacktips.api;
2+
3+
import com.stacktips.model.Product;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.springframework.http.MediaType;
6+
import org.springframework.web.bind.annotation.*;
7+
8+
import java.util.List;
9+
10+
@Slf4j
11+
@RestController
12+
@RequestMapping(value = "/products", produces = {MediaType.APPLICATION_JSON_VALUE})
13+
public class ProductController {
14+
15+
@GetMapping
16+
public List<Product> getProducts() {
17+
log.info("ProductController::getProducts()");
18+
19+
return List.of(
20+
new Product(100L, "iPhone 12", 600.0),
21+
new Product(101L, "iPhone 13", 800.0),
22+
new Product(102L, "iPhone 14", 1000.0)
23+
);
24+
}
25+
26+
@GetMapping(value = "/{productId}")
27+
public Product getProduct(@PathVariable(value = "id") Long id) {
28+
//Your service logic goes here
29+
return new Product(100L, "iPhone 12", 600.0);
30+
}
31+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.stacktips.model;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
import lombok.Setter;
6+
7+
@AllArgsConstructor
8+
@Getter
9+
@Setter
10+
public class Product {
11+
Long id;
12+
String name;
13+
Double price;
14+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
server.servlet.context-path=/api/1.0

c002-run-on-startup/src/test/java/com/stacktips/SpringBootRestApiApplicationTests.java renamed to YT001-setting-context-path/src/test/java/com/stacktips/ExampleApplicationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.springframework.boot.test.context.SpringBootTest;
55

66
@SpringBootTest
7-
class SpringBootRestApiApplicationTests {
7+
class ExampleApplicationTests {
88

99
@Test
1010
void contextLoads() {

0 commit comments

Comments
 (0)