25-03-10
๐ Daily Reportโ
๐ ํ๋ก์ ํธ ์ํฉโ
2์๊ฐ ๋ฐ ์ค๋ค. ๋ ์ด์์ ์ค๋ช
์ ์๋ตํ๋ค.
ํผ๊ณคํจ๊ณผ ๋ณ๊ฐ๋ก, ์ง๊ธ ์ฝ๋ ์์ง๋ฉด ์ง์ง ๋งํ ์๋ ์๋ค๋ ์๊ฐ์ด ๋๋๊น ์ด์ธ์ ์ธ ์ง์ค๋ ฅ์ด ๋์ค๊ณ ์๋ค.
๊ทธ๋ฆฌ๊ณ ์๋ํฌ์ธํธ๋ก ๋๋ฆด ์ ์๋๊ฑด ๋ค ๋๋ ค์, ์นดํ์นด / ์ ๋ ์นด ์ ๋ถ ํด๋ผ์ฐ๋ ์๋ฒ๋ก ๋๋ฆฌ๊ณ ๋ก์ปฌ์ ์ต๋ํ ์์์ ์๋ผ๋ ค ํ๊ณ ์๋ค.
Java๋ก ๊ฐ๋ฐ๋ IDE์์ Java๋ก ๊ฐ๋ฐ๋ ํ๋ ์์ํฌ๋ฅผ ๋๋ฆฌ๊ณ ๊ฑฐ๊ธฐ์ ํฌ๋กฌ๊น์ง ํญ ๋ญ๋ญํ๊ฒ ๋์๋จ๋ค?
8GB๊ฐ ๊ณ ์ ์ข ๋ฒ๋ฒ ๊ฑฐ๋ฆฌ๋ ๊ฒ์ผ๋ก ๋๋จ์ ๊ฐ์ฌํด์ผ ํ๋ค;
์ ๋ฐ ์ฌํด๋ ๋ ธํธ๋ถ RAM ํ์ฅ์ ํ์.
๐ @Value
์ Constructor ์ฃผ์
โ
CoolSMS๋ก ๋ฌธ์ ๋ฐ์ก ๊ธฐ๋ฅ ๊ตฌํํ๋ค๊ฐ ๋ค์ ํ๋ฒ ์๊ธฐํ๊ฒ ๋ ๋ถ๋ถ์ธ๋ฐ,
๋ค์๊ณผ ๊ฐ์ด ์์ฑ์ ์ฃผ์
์ ํ๋ฉด @Value
๋ก ์ฃผ์
ํ๋ ค๋ ๊ฐ๋ค์ ์์ฑ์ ์ฃผ์
์์ ์ null์ด๋ค.
๊ทธ ์ด์ ๋, ์ด ๋ ํผ๋ฐ์ค์์ ๋ต์ ์ฐพ์ ์ ์๋ค.
Spring won't inject the properties' values until the object is fully instantiated.
์ ๋ฆฌํ๋ฉด, ์์ฑ์ ํธ์ถ -> ์ธ์คํด์คํ -> property ๊ฐ ์ฃผ์ ์์ผ๋ก ์ผ์ด๋๊ธฐ ๋๋ฌธ์ด๋ค.
@Component
public class SmsUtil {
@Value("${coolsms.apiKey}")
private String SMS_API_KEY;
@Value("${coolsms.secret}")
private String SMS_SECRET;
@Value("${coolsms.sender}")
private String SMS_SENDER; // ๋ฐ์ ๋ฒํธ
@Value("${coolsms.enable}")
private boolean SMS_ENABLED; // false๋ฉด ๋ก๊ทธ๋ง ์ฐํ๊ณ ์ค์ ๋ฌธ์ ์ ์ก์ ์คํต๋จ
// ...
// CoolSMS API ์ค์
private final DefaultMessageService messageService;
public SmsUtil() {
this.messageService = NurigoApp.INSTANCE.initialize(SMS_API_KEY, SMS_SECRET, "https://api.coolsms.co.kr");
}
// ...
}
๋ฐ๋ผ์ ์๋จ์ ์ฝ๋์์๋ ๋ค์๊ณผ ๊ฐ์ ์๋ฌ๋ฅผ ๋ง๊ฒ ๋๋ค.
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.ssginc.commonservice.util.SmsUtil]: Constructor threw exception
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:222)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:122)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1337)
... 50 common frames omitted
Caused by: java.lang.NullPointerException: Parameter specified as non-null is null: method net.nurigo.sdk.NurigoApp.initialize, parameter apiKey
๊ทธ๋ฌ๋ฏ๋ก ๋ค์๊ณผ ๊ฐ์ด ์์ฑ์๋ฅผ ์์ ํด์ผ ํ๋ค.
@Autowired
public SmsUtil(@Value("${coolsms.apiKey}") String SMS_API_KEY, @Value("${coolsms.secret}") String SMS_SECRET) {
this.messageService = NurigoApp.INSTANCE.initialize(SMS_API_KEY, SMS_SECRET, "https://api.coolsms.co.kr");
}
๐ ๋ฌธ์ ๋ฐ์ก ๊ธฐ๋ฅ ๊ตฌํ์ ์ฃผ์์ฌํญโ
๋ฒํธ๋์ฉ ๋ฌธ์์ฐจ๋จ์๋น์ค์ ๊ฐ์ ๋์ด ์์ ์ ์์.........
ํด์ง ์ ์ฒญ ๋ฃ์ด๋ ๋ฐ์๊น์ง ์ต์ 1~2์ผ ๊ฑธ๋ฆฐ๋ค๊ณ ํ๋ ์ง์ ์ ๊ธํ๊ฒ ๊ตฌํํ์ง ๋ง ๊ฒ.