๐ŸŒป JAVA

๐ŸŒป JAVA/JUnit

@WebMvcTest ์ž‘์„ฑ ์‹œ ์˜์กด์„ฑ ์—๋Ÿฌ

ํ™˜๊ฒฝ Spring boot 2.7.1 Spring Security JUnit 5 Controller ํ…Œ์ŠคํŠธ๋ฅผ ํ•˜๊ธฐ์œ„ํ•ด ๋ถˆํ•„์š”ํ•œ ์˜์กด์„ฑ๋“ค์€ ๊ฑท์–ด๋‚ด๊ณ  WebMvcTest ์–ด๋…ธํ…Œ์ด์…˜์„ ๋ถ™์—ฌ์„œ ์ปจํŠธ๋กค๋Ÿฌ ๋ ˆ์ด์–ด๋งŒ ๊ฐ€๋ณ๊ณ  ๋น ๋ฅด๊ฒŒ ํ…Œ์ŠคํŠธ๋ฅผ ์ง„ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. WebMvcTest ์–ด๋…ธํ…Œ์ด์…˜์„ ๋ถ™์ด๊ฒŒ ๋˜๋ฉด, MVC ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•œ ์˜์กด์„ฑ๋“ค์ด Spring Contetxt์— ์˜ฌ๋ผ๊ฐ€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. Using this annotation will disable full auto-configuration and instead apply only configuration relevant to MVC tests (i.e. @Controller, @ControllerAdvice, @JsonComponent, Converter/Generi..

๐ŸŒป JAVA/์ •๋ฆฌ์ •๋ฆฌ์ •๋ฆฌ

[JAVA] System.getProperties๋กœ ํ”„๋กœํผํ‹ฐ ๊ฐ’ ๋ฐ›๊ธฐ

System.getProperties๋กœ ํ”„๋กœํผํ‹ฐ ๊ฐ’ ๋ฐ›๊ธฐ ๊ธฐ์กด์—๋Š” ์ด๋Ÿฐ์‹์œผ๋กœ ๋„˜๊ฒจ์ฃผ๋ฉด, $ java -jar XXX.jar arg1 arg2 arg3 ์ž๋ฐ”์—์„œ๋Š” ์ด๋ ‡๊ฒŒ ๋ฐ›์œผ๋ฉด ๋œ๋‹ค. public class Main { public static void main(String[] args) { String arg1 = args[0]; String arg2 = args[1]; String arg3 = args[2]; } } ๋ฌธ์ œ๋Š” ๋„์ปค ์ด๋ฏธ์ง€๋ฅผ ๋งŒ๋“ค๋‹ค๊ฐ€ ENV ๋ณ€์ˆ˜๋กœ ์‹คํ–‰์‹œํ‚ค๊ฒŒ๋” ํ•˜๋ ค๋Š”๋ฐ ์ž๊พธ ENV๊ฐ€ ์•ˆ๋‹ด๊ฒจ๋‚˜๊ฐ€์„œ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋ณด๋‹ค๊ฐ€ ๋ฐœ๊ฒฌํ–ˆ๋‹ค. ๋ฐ”๋กœ.. System.getProperty("key") ํŒŒ๋ผ๋ฏธํ„ฐ ๋„˜๊ฒจ์ค„ ๋•Œ๋Š”, -D์˜ต์…˜์œผ๋กœ -D{key}={value} ์ด๋Ÿฐ์‹์œผ๋กœ ๋„˜๊ฒจ์ฃผ๋ฉด ๋œ๋‹ค. $ java -D..

๐ŸŒป JAVA/์ž๋ฐ” ORM ํ‘œ์ค€ JPA ํ”„๋กœ๊ทธ๋ž˜๋ฐ

LazyInitializationException์ด ๋‚˜๋Š” ์ด์œ  (feat. ํŠธ๋žœ์žญ์…˜)

์ฝ”๋“œ ์ „์ฒด ์ฝ”๋“œ๋Š” Github์— ์žˆ์Šต๋‹ˆ๋‹ค :) TeamServiceTest @RunWith(SpringRunner.class) @SpringBootTest public class TeamServiceTest { @Autowired private TeamService teamService; @Before public void setup() { Team team = new Team(null, "team", new ArrayList()); for (int i = 1; i t.getMembers().get(0).getName()); } } TeamRepository @Repository public interface TeamRepository extends JpaRepository { } ์ƒํ™ฉ Serivce๋‹จ์—..

๐ŸŒป JAVA/์ •๋ฆฌ์ •๋ฆฌ์ •๋ฆฌ

ํ•ด์‹œ(Hash)?์†”ํŠธ(Salt)? ํŒจ์Šค์›Œ๋“œ ์•”ํ˜ธํ™” ๋Œ€ํ•ด์„œ

ํ•ด์‹œ๋ฅผ ํ†ตํ•œ ์•”ํ˜ธํ™” Hash(ํ•ด์‹œ)๋ž€? ๋‹จ๋ฐฉํ–ฅ ์•”ํ˜ธํ™” ๊ธฐ๋ฒ•์œผ๋กœ ํ•ด์‹œ ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ์•”ํ˜ธํ™” ๋œ ๋ฌธ์ž์—ด์„ ๋งŒ๋“œ๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ex) SHA-256, Bcrypt .. ์‚ฌ์šฉ์ž์˜ ํŒจ์Šค์›Œ๋“œ๋Š” ํ‰๋ฌธ์œผ๋กœ ์ €์žฅํ•˜๋Š” ๊ฒƒ์€ ์œ„ํ—˜ํ•œ ์ผ์ž…๋‹ˆ๋‹ค. ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ๋ณดํ†ต ํ•ด์‹œ ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ์•”ํ˜ธํ™”๋ฅผ ์ง„ํ–‰ํ•˜๊ฒŒ ๋˜๋Š”๋ฐ, ์ด๋„ ๊ทธ๋ ‡๊ฒŒ ์•ˆ์ „ํ•œ ๊ฒƒ์€ ์•„๋‹™๋‹ˆ๋‹ค. ๊ณต๊ฒฉ์ž๊ฐ€ ๋ชจ๋“  ํ‰๋ฌธ์„ ํ•ด์‹œํ™”ํ•˜์—ฌ ๋Œ€์กฐ๋ฅผ ํ•˜์—ฌ ํŒจ์Šค์›Œ๋“œ๋ฅผ ์•Œ์•„๋‚ผ ์ˆ˜๋„ ์žˆ๋‹ค๋Š” ๋œป์ž…๋‹ˆ๋‹ค. ํ•ด์ปค๋Š” ๋ฌดํ•œ๋Œ€๋กœ ๊ณต๊ฒฉ์„ ํ•œ๋‹ค๋ฉด ์–ด๋–ค ์•”ํ˜ธํ™”๋ฅผ ํ•ด๋„ ํŒจ์Šค์›Œ๋“œ๋ฅผ ์•Œ์•„๋‚ผ ์ˆ˜ ์žˆ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ํ•ด์ปค๋“ค์ด ๋ฌดํ•œ๋Œ€๋กœ ๊ณต๊ฒฉ์„ ํ•  ์ˆ˜ ์žˆ์„๊นŒ์š”? X ํ•ด๋…ํ•  ๋•Œ ์กฐ๊ธˆ์ด๋ผ๋„ ๋” ์•”ํ˜ธํ™”๋ฅผ ํ•ด์„œ ํ•ด์ปค๋“ค์—๊ฒŒ ๋‹จ ๋ช‡์ดˆ๋ผ๋„ ์ง€์—ฐ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค๋ฉด ํ•ด์ปค๋“ค์—๊ฒŒ๋Š” ์น˜๋ช…์ ์ธ ์‹œ๊ฐ„์ด ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋”๋ณด๊ธฐ ์•”ํ˜ธ๋ฅผ ํ•ด๋…ํ•˜๋Š”๋ฐ ๊ฑธ๋ฆฌ..

๐ŸŒป JAVA/์ •๋ฆฌ์ •๋ฆฌ์ •๋ฆฌ

[JAVA] properties ๊ฐ’ ์ฝ์–ด์˜ค๊ธฐ

application.properties people.name="iseunghan" people.age=26 people.city="Daejeon" Main.java public class Main { static String name; static String age; static String city; private static void read_properties() { // resource ์œ„์น˜ String resource = "META-INF/application.properties"; Properties properties = new Properties(); try { InputStream inputStream = Main.class.getClassLoader().getResourceAsStr..

๐ŸŒป JAVA/์ •๋ฆฌ์ •๋ฆฌ์ •๋ฆฌ

intellij์—์„œ Java ํ”„๋กœ์ ํŠธ jar ํŒŒ์ผ ์ƒ์„ฑํ•˜๊ธฐ

์ž๋ฐ” ํ”„๋กœ์ ํŠธ๋ฅผ intellij์—์„œ jar ํŒŒ์ผ ๋งŒ๋“œ๋Š” ๋ฒ• ๊ฐ„๋‹จํ•œ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ์„ ํ–ˆ์Šต๋‹ˆ๋‹ค. hello world!๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ๋ฉ”์ธ ํด๋ž˜์Šค์ž…๋‹ˆ๋‹ค. cmd + :๋กœ ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ ์„ค์ •์œผ๋กœ ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค. (Mac OS ๋‹จ์ถ•ํ‚ค) Artifacts -> + -> JAR -> From modules ... ํด๋ฆญ! Main Class๋ฅผ ์ง€์ •ํ•ด์ค๋‹ˆ๋‹ค. ์ด๋•Œ ํŒจํ‚ค์ง€๋ช…๊นŒ์ง€ ๋‹ค ์ ์–ด์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค! ์ดํ›„์— Apply -> OK๋ฅผ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค. ์ด์ œ intellij ์ƒ๋‹จ๋ฐ”์—์„œ build -> artifacts๋ฅผ ํด๋ฆญํ•ด์ค๋‹ˆ๋‹ค. build๋ฅผ ํด๋ฆญํ•ด์ค๋‹ˆ๋‹ค. out/artifacts/[project๋ช…]์— jar ํŒŒ์ผ์ด ์ƒ์„ฑ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. jar ํŒŒ์ผ ์‹คํ–‰ํ•˜๊ธฐ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์‹คํ–‰๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

iseunghan
'๐ŸŒป JAVA' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (2 Page)