๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ฐ˜์‘ํ˜•

๊ฐœ๋ฐœ/JAVA24

[JAVA] ์ ‘๊ทผ์ œํ•œ์ž๊ฐ€ private์ธ ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๋ฐฉ๋ฒ• ์ฃผ๋ฌธ๋ฒˆํ˜ธ๋ฅผ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๊ฐ–๋Š” Order ํด๋ž˜์Šค์˜ canCancel ๋ฉ”์†Œ๋“œ๊ฐ€ private๋กœ ์„ ์–ธ๋˜์–ด ์žˆ์„ ๋•Œ ์ด ๋ฉ”์†Œ๋“œ๋ฅผ ์™ธ๋ถ€์—์„œ ํ˜ธ์ถœํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค. Order order = new Order(); Method method = order.getClass().getDeclaredMethod("canCancel", Order.class); method.setAccessible(true); boolean result = (boolean)method.invoke(order, "์ฃผ๋ฌธ๋ฒˆํ˜ธ"); 2022. 10. 13.
[JAVA] ๋ฐฐ์น˜(bat), ์‰˜(sh) ์‹คํ–‰ํ•˜๊ธฐ command ์ฐฝ์—์„œ๋งŒ ์‹คํ–‰ํ•˜๋˜ ๋ฐฐ์น˜ ํ˜น์€ ์‰˜์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ์„ ์ž๋ฐ”์—์„œ ์‹คํ–‰ํ•ด์•ผํ•  ์ผ์ด ์ƒ๊ฒจ ์•„๋ž˜์™€ ๊ฐ™์ด ์ž‘์„ฑํ•˜์˜€๋‹ค. result๊ฐ’์ด 0์ด๋ฉด ์‹คํ–‰ ์„ฑ๊ณตํ•œ ๊ฒƒ! public boolean runXXXX(String xxxx) { boolean result = false; String filePath = "ํŒŒ์ผ path"; super.logger.debug("file path : " + filePath); File file = new File(filePath); try { if(file.exists()){ CommandLine cmdLine = CommandLine.parse(filePath+" "+req_id); DefaultExecutor executor = new DefaultExecutor(); try.. 2022. 5. 18.
[JAVA] KeyStore์— Root ์ธ์ฆ์„œ ๋“ฑ๋กํ•˜๊ธฐ(SSLHandshakeException, PKIXException) ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๊ด€์—์„œ ๋ฐœ๊ธ‰๋ฐ›์€ ssl์ธ์ฆ์„œ๊ฐ€ ์•„๋‹ˆ๊ฑฐ๋‚˜ ๋ณดํŽธ์ ์œผ๋กœ ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๊ด€์ด์ง€๋งŒ JAVA์—์„œ ์‹ ๋ขฐํ•˜์ง€ ๋ชปํ•˜๋Š” ๊ฒฝ์šฐ HTTPSํ†ต์‹ ์„ ํ•˜๊ฒŒ ๋  ๋•Œ SSLHandshakeException ํ˜น์€ PKIXException ์—๋Ÿฌ๊ฐ€ ๋ฐธ์ƒํ•œ๋‹ค. (ํ•ด๋‹น exception์ด ๋ฐœ์ƒํ•œ๊ฑด TLS๋ฒ„์ „์ด ๋‹ค๋ฅด๋‹ค๊ฑฐ๋‚˜.. ๋‹ค๋ฅธ ์ด์œ ๊ฐ€ ์›์ธ์ผ ์ˆ˜๋„ ์žˆ์ง€๋งŒ ๋ณธ ํฌ์ŠคํŒ…์—์„œ๋Š” ์‹ ๋ขฐํ•˜์ง€ ์•Š๋Š” Root์ธ์ฆ์„œ์ผ๋•Œ์— ๋Œ€ํ•ด ์ž‘์„ฑํ•˜๊ฒ ๋‹ค!) ์ด ๊ฒฝ์šฐ SSL์ธ์ฆ์„œ์˜ ์ƒ์œ„ ์ธ์ฆ๊ธฐ๊ด€์„ JAVA์˜ keystore์— ์ถ”๊ฐ€ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค. ์ž๋ฐ”์˜ keystore์˜๊ฒฝ๋กœ๋Š” JAVA_HOME/ib/security/cacerts ์ด๋‹ค. ๋ฐฉ๋ฒ•1. ๋ช…๋ น์–ด ์ด์šฉ keytool -importcert -keystore "cacerts ๊ฒฝ๋กœ" -storepass "์ €์žฅ.. 2022. 5. 18.
[JAVA] Runnable ๊ณผ Thread์˜ ์ฐจ์ด ์œ„ ์˜ˆ์ œ ์†Œ์Šค์— ์žˆ๋Š” Runnable์ด๋ž€ ๊ฐ„๋‹จํ•˜๊ฒŒ ๋งํ•ด์„œ Thread๋ฅผ ์ธํ„ฐํŽ˜์ด์Šคํ™”ํ•œ ๊ฒƒ์ธ๋ฐ, Java์—์„œ๋Š” ๋‹ค์ค‘ ์ƒ์†์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋ฏ€๋กœ Thread๋ฅผ ์ƒ์† ๋ฐ›์ง€ ๋ชปํ•˜๋Š” ๊ฒฝ์šฐ extends Thread๊ฐ€ ์•„๋‹Œ implements๋กœ Runnable๋กœ ์ฒ˜๋ฆฌ ํ•  ์ˆ˜ ์žˆ๋‹ค. extends Thread public class ThreadTest extends Thread { public void run() { System.out.println("thread"); } } ThreadTest threadTest = new ThreadTest(); threadTest.start(); implements Runnable public class ThreadTest implements Runnable { public void .. 2022. 5. 16.
[JAVA] ๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ ๋ฐฉ๋ฒ• - Thread JAVA์—์„œ ๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•ด ์Šค๋ ˆ๋“œ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‹ค๋ฅธ ์„œ๋ฒ„๋กœ ์š”์ฒญ์„ ๋ณด๋‚ผ ๋•Œ ๋น„๋™๊ธฐ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์ž‘์„ฑํ•˜๋ฉด ๋œ๋‹ค. public void request() { Thread thread = new Thread(new Runnable() { @Override public void run() { //์ฝ”๋“œ ์ž‘์„ฑ } }); thread.start(); } ํ•˜์ง€๋งŒ ๋ณ‘๋ ฌ์ž‘์—… ์ฒ˜๋ฆฌ๋Ÿ‰์ด ๋งŽ์•„์ง€๋ฉด ์„ฑ๋Šฅ์ด ์ €ํ•˜๋˜๋Š”๋ฐ, ์ด๋ฅผ ๋ง‰๊ธฐ ์œ„ํ•ด์„œ ์Šค๋ ˆ๋“œ ํ’€์„ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค. ์Šค๋ ˆ๋“œํ’€์€ ์Šค๋ ˆ๋“œ ๊ฐœ์ˆ˜๋ฅผ ๋ฏธ๋ฆฌ ์ •ํ•ด ๋†“๊ณ , ์ž‘์—… ํ์— ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ๋ฏธ๋ฆฌ ์ƒ์„ฑํ•ด ๋†“์€ ์Šค๋ ˆ๋“œ๋“ค์—๊ฒŒ ํ• ๋‹นํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค. JDK 1.5๋ถ€ํ„ฐ๋Š” java.util.concurrent Package์— ExecutorService ์ธํ„ฐํŽ˜์ด์Šค์™€ Ex.. 2022. 4. 27.
[JAVA] java.lang.NoSuchMethodError: org.apache.logging.log4j.Logger.error(Ljava/lang/String;Ljava/lang/Object;)V] ๊ณตํ†ต ์‚ฌ์šฉ๋˜๋Š” ๊ธฐ๋Šฅ์„ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๋งŒ๋“ค์—ˆ๋‹ค. ์ด ๊ณตํ†ต ๊ธฐ๋Šฅ์„ ๋ชจ์•„๋‘” ํ”„๋กœ์ ํŠธ์˜ pom.xml์—๋Š” log4j-api.jar๋ฅผ ์„ ์–ธํ•˜์˜€๊ณ , ์ด๋ฅผ ์ด์šฉํ•˜์—ฌ log๋ฅผ ๋‚จ๊ฒผ๋‹ค. ex) log.error("์—๋Ÿฌ ๋ฐœ์ƒ");, log.debug("์ฒ˜๋ฆฌ ์™„๋ฃŒ"); ํ•˜์ง€๋งŒ ๋‹ค๋ฅธ ํ”„๋กœ์ ํŠธ์—์„œ ๊ณตํ†ต ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋‹ˆ ๋กœ๊ทธ๋ฅผ ๋‚จ๊ธฐ๋Š” ๋ถ€๋ถ„์—์„œ ์•„๋ž˜์™€ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€๋‹ค. Servlet.service() for servlet [appServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: org.apache.logging.log4j.Logger.error(Lja.. 2022. 3. 25.
[JAVA] HttpClient ๋กœ๊ทธ ๋‚จ๊ธฐ๊ธฐ, ๋กœ๊ทธ ๋ ˆ๋ฒจ ์ œ์–ดํ•˜๊ธฐ org.apache.http.client.HttpClient ์˜ ๋กœ๊ทธ๊ฐ€ ๋กœ๊น…๋˜์ง€ ์•Š์•„ ์‚ดํŽด๋ณด๋‹ˆ JCL๊ณผ slf4j์˜ ๋ธŒ๋ฆฟ์ง€ ์—ญํ• ์„ ํ•˜๋Š” 'jcl-over-slf4j' ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ๋น ์ ธ์žˆ์—ˆ๋‹ค. ์ด ๋ถ€๋ถ„์— ๋Œ€ํ•œ ์ž์„ธํ•œ ์„ค๋ช…์€ ์ด ๋ธ”๋กœ๊ทธ๋ฅผ ์ฐธ๊ณ ํ•˜๊ธฐ! https://dololak.tistory.com/635 pom.xml์— jcl-over-slf4j ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ์—ˆ๊ณ  org.slf4j jcl-over-slf4j ${slf4j.version} log4j2๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์—ˆ๊ธฐ์— log4j2.xml์— ์•„๋ž˜์™€ ๊ฐ™์ด ์ถ”๊ฐ€ํ•ด์ฃผ์—ˆ๋‹ค. 2022. 3. 25.
[JAVA] jackson -JsonInclude ์†์„ฑ (null, empty๋“ฑ์˜ ๋ฐ์ดํ„ฐ ์ œ์™ธํ•˜๊ธฐ) VO๊ฐ์ฒด๋ฅผ JSON์œผ๋กœ ๋ณ€ํ™˜ํ•  ๋•Œ ํฌํ•จ๋˜๋ฉด ์•ˆ๋˜๋Š” ๋ณ€์ˆ˜์— @JsonIgnore ์–ด๋…ธํ…Œ์ด์…˜์„ ์„ ์–ธํ•˜์—ฌ JSON์— ํฌํ•จ๋˜์ง€ ์•Š๋„๋ก ํ•  ์ˆ˜ ์žˆ๋‹ค. ํ•˜์ง€๋งŒ ์ƒํ™ฉ์— ๋”ฐ๋ผ json ํฌํ•จ ์—ฌ๋ถ€๊ฐ€ ๋‹ฌ๋ผ์ง€๋Š” ๊ฒฝ์šฐ ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค. ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); //null์ธ ๋ฐ์ดํ„ฐ๋ฅผ ์ œ์™ธํ•˜๊ณ  json ์ƒ์„ฑ mapper.writeValueAsString(testVO); VO์— default๋กœ ์ ์šฉํ•˜๋ ค๋ฉด VO Class์— @JsonInclude ์–ด๋…ธํ…Œ์ด์…˜์„ ์„ ์–ธํ•˜๋ฉด ๋œ๋‹ค. @JsonInclude(JsonInclude.Include.NON_NULL) .. 2022. 3. 11.
728x90
๋ฐ˜์‘ํ˜•