728x90
개요: spring context의 bean을 생성할 때 기존 메소드를 사용해서 생성해보자
package com.in28minutes.learn_spring_framework;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
record Person(String name, int age) {};
record Address(String firstLine, String city) {};
@Configuration
public class HelloWorldConfiguration {
@Bean
public String name() {
return "Ranga";
}
@Bean
public int age() {
return 15;
}
@Bean
public Person person() {
return new Person("tomhoon", 30);
}
@Bean(name = "address2")
public Address address() {
return new Address("bakerStreet", "Anyang");
}
@Bean
public Person person2MethodCall() {
return new Person(name(), age());
}
}
person2MethodCall 영역을 보면
new Person 객체 생성시 파라미터를
name(), age() 두가지를 주고 있다.
메인에서 실행시 잘 되는지 확인해보자
'서버' 카테고리의 다른 글
SpringBoot에서 서버를 켰을 때 compile 에러가 나는 경우 (1) | 2024.08.23 |
---|---|
Spring boot - Context Bean 생성하기 실습 (1) | 2024.08.22 |
Springboot - record 사용해보기 (0) | 2024.08.22 |
Springboot - Spring Context 다루기 (0) | 2024.08.22 |
github action - 자체 runner 내 컴퓨터에다가 생성하기 (0) | 2024.08.21 |