Skip to content

Commit 07ba993

Browse files
committed
primary bean & annotation
1 parent 4336f5a commit 07ba993

Some content is hidden

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

56 files changed

+145
-42
lines changed

.DS_Store

0 Bytes
Binary file not shown.
17 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

spring_basic/.gradle/7.3/dependencies-accessors/gc.properties

Whitespace-only changes.
Binary file not shown.
Binary file not shown.

spring_basic/.gradle/7.3/gc.properties

Whitespace-only changes.
17 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

spring_basic/.gradle/7.4/dependencies-accessors/gc.properties

Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

spring_basic/.gradle/7.4/gc.properties

Whitespace-only changes.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#Fri Aug 20 22:09:32 KST 2021
2-
gradle.version=7.1.1
1+
#Thu Dec 07 00:28:18 KST 2023
2+
gradle.version=7.4
Binary file not shown.
8 Bytes
Binary file not shown.

spring_basic/.idea/compiler.xml

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spring_basic/.idea/gradle.xml

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spring_basic/.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spring_basic/.idea/runConfigurations.xml

-10
This file was deleted.

spring_basic/.idea/spring_basic.iml

-9
This file was deleted.

spring_basic/build.gradle

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
plugins {
2-
id 'org.springframework.boot' version '2.5.4'
3-
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
42
id 'java'
3+
id 'org.springframework.boot' version '3.2.0'
4+
id 'io.spring.dependency-management' version '1.1.4'
55
}
66

77
group = 'hello'
88
version = '0.0.1-SNAPSHOT'
9-
sourceCompatibility = '11'
9+
10+
java {
11+
sourceCompatibility = '17'
12+
}
1013

1114
configurations {
1215
compileOnly {
@@ -18,20 +21,13 @@ repositories {
1821
mavenCentral()
1922
}
2023

21-
dependencies {
22-
implementation 'org.springframework.boot:spring-boot-starter'
2324

25+
dependencies {
2426
compileOnly 'org.projectlombok:lombok'
2527
annotationProcessor 'org.projectlombok:lombok'
26-
testCompileOnly 'org.projectlombok:lombok'
27-
testAnnotationProcessor 'org.projectlombok:lombok'
28-
29-
30-
testImplementation ('org.springframework.boot:spring-boot-starter-test'){
31-
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
32-
}
28+
testImplementation 'org.springframework.boot:spring-boot-starter-test'
3329
}
3430

35-
test {
31+
tasks.named('test') {
3632
useJUnitPlatform()
3733
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package jpa.demo.controller;
2+
3+
import jpa.demo.controller.annotation.MainOrderService;
4+
import jpa.demo.domain.item.Book;
5+
import jpa.demo.domain.item.Movie;
6+
import jpa.demo.repository.BookRepository;
7+
import jpa.demo.repository.ItemRepository;
8+
import jpa.demo.repository.MovieRepository;
9+
import jpa.demo.service.OrderService;
10+
import lombok.RequiredArgsConstructor;
11+
import lombok.extern.slf4j.Slf4j;
12+
import org.springframework.beans.factory.annotation.Autowired;
13+
import org.springframework.beans.factory.annotation.Qualifier;
14+
import org.springframework.web.bind.annotation.PostMapping;
15+
import org.springframework.web.bind.annotation.RequestMapping;
16+
import org.springframework.web.bind.annotation.RestController;
17+
18+
@RequestMapping("/bean")
19+
@Slf4j
20+
@RestController
21+
public class BeanTestController {
22+
23+
private final OrderService orderService;
24+
25+
@Autowired
26+
public BeanTestController(@MainOrderService OrderService orderService) {
27+
this.orderService = orderService;
28+
}
29+
30+
@PostMapping("/primary")
31+
public void test(){
32+
log.info("OrderService = {}", orderService.order());
33+
}
34+
}

복습/src/main/java/jpa/demo/controller/TestController.java 복습/src/main/java/jpa/demo/controller/ExtendTestController.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
import jpa.demo.repository.BookRepository;
66
import jpa.demo.repository.ItemRepository;
77
import jpa.demo.repository.MovieRepository;
8+
import jpa.demo.service.OrderService;
89
import lombok.RequiredArgsConstructor;
910
import lombok.extern.slf4j.Slf4j;
1011
import org.springframework.web.bind.annotation.GetMapping;
1112
import org.springframework.web.bind.annotation.PostMapping;
1213
import org.springframework.web.bind.annotation.RequestMapping;
1314
import org.springframework.web.bind.annotation.RestController;
1415

16+
@RequestMapping("/extend")
1517
@Slf4j
1618
@RestController
1719
@RequiredArgsConstructor
18-
public class TestController {
20+
public class ExtendTestController {
1921

2022
private final ItemRepository itemRepository;
2123
private final BookRepository bookRepository;
@@ -31,5 +33,6 @@ public void test(){
3133
log.info("items = {}", itemRepository.findAll());
3234
log.info("books = {}", bookRepository.findAll());
3335
log.info("movie = {}", movieRepository.findAll());
36+
3437
}
3538
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package jpa.demo.controller.annotation;
2+
3+
import org.springframework.beans.factory.annotation.Qualifier;
4+
5+
import java.lang.annotation.*;
6+
7+
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE, ElementType.ANNOTATION_TYPE})
8+
@Retention(RetentionPolicy.RUNTIME)
9+
@Inherited
10+
@Documented
11+
@Qualifier("mainOrderService")
12+
public @interface MainOrderService {
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package jpa.demo.service;
2+
3+
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.springframework.context.annotation.Primary;
6+
import org.springframework.stereotype.Component;
7+
8+
@Slf4j
9+
@Component
10+
@Primary
11+
public class AOrderService implements OrderService {
12+
13+
@Override
14+
public String order() {
15+
return "A 주문 호출";
16+
}
17+
18+
@Override
19+
public void cancel() {
20+
log.info("A 주문 취소 호출");
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package jpa.demo.service;
2+
3+
import jpa.demo.controller.annotation.MainOrderService;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.springframework.beans.factory.annotation.Qualifier;
6+
import org.springframework.stereotype.Component;
7+
8+
@Slf4j
9+
@Component
10+
@MainOrderService
11+
public class BOrderService implements OrderService {
12+
@Override
13+
public String order() {
14+
return "B 주문 호출";
15+
}
16+
17+
@Override
18+
public void cancel() {
19+
log.info("B 주문 취소 호출");
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package jpa.demo.service;
2+
3+
public interface OrderService {
4+
5+
public String order();
6+
7+
public void cancel();
8+
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package jpa.demo.bean;
2+
3+
import jpa.demo.controller.annotation.MainOrderService;
4+
import jpa.demo.service.OrderService;
5+
import org.assertj.core.api.Assertions;
6+
import org.junit.jupiter.api.Disabled;
7+
import org.junit.jupiter.api.DisplayName;
8+
import org.junit.jupiter.api.Test;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.beans.factory.annotation.Qualifier;
11+
import org.springframework.boot.test.context.SpringBootTest;
12+
13+
import static org.assertj.core.api.Assertions.*;
14+
15+
@SpringBootTest
16+
public class PrimaryBeanTest {
17+
18+
// @Autowired private OrderService orderService;
19+
@Autowired @MainOrderService OrderService orderService;
20+
@Test
21+
@DisplayName("@Primary")
22+
public void primaryTest(){
23+
// assertThat(orderService.order()).isEqualTo("A 주문 호출");
24+
assertThat(orderService.order()).isEqualTo("B 주문 호출");
25+
}
26+
}

0 commit comments

Comments
 (0)