@PostConstruct์ ์์กด์ฑ ์ฃผ์
์ด ์๋ฃ๋ ํ์ ์ํ๋์ด์ผ ํ๋ ๋ฉ์๋์ ์ฌ์ฉํ๋ ์ด๋
ธํ
์ด์
์ด๋ค.
- ํด๋น ์ด๋
ธํ
์ด์
์ด ์ ์ธ๋ ๋ฉ์๋๋ ๋ค๋ฅธ ๋ฆฌ์์ค์์ ํธ์ถ๋์ง ์์๋ ์ํ๋๋ค.
- ์์ฑ์๋ณด๋ค ๋ฆ๊ฒ ํธ์ถ๋๋ค.
- ์์ฑ์ ํธ์ถ
- ์์กด์ฑ ์ฃผ์
(
@RequiredArgsConstructor or @Autowired)
@PostConstruct ํธ์ถ
- ์์ฑ์๊ฐ ํธ์ถ๋ ๋ bean์ ์ด๊ธฐํ ์ ์ผ๋ก,
@PostConstruct๋ฅผ ์ฌ์ฉํ๋ฉด bean์ด ์ด๊ธฐํ ๋จ๊ณผ ๋์์ ์์กด์ฑ์ ํ์ธํ ์ ์๋ค.
- bean์ ์๋ช
์ฃผ๊ธฐ์์ ๋จ ํ ๋ฒ๋ง ์ํ๋๋ฏ๋ก ์ด๊ธฐํ ๋ฉ์๋์ ์ ์ธํ๋ฉด ์ฌ๋ฌ ๋ฒ ์ด๊ธฐํ๋๋ ๋ฌธ์ ๋ฅผ ๋ฐฉ์งํ ์ ์๋ค.
@Service
@RequiredArgsConstructor
public class testService {
// ...
private final Map<String, Object> serviceSetups = new HashMap<>();
@PostConstruct
public void setup() {
serviceSetups.put("service", Service.TEST);
serviceSetups.put("applicationType", ApplicationType.PROTOTYPE);
serviceSetups.put("message", "This setup is occured in PostConstruct.");
}
}