๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ’ปWEB BackEnd/ํ”„๋ ˆ์ž„์›Œํฌ Spring

(9)
์˜์กด ๊ฐ์ฒด ์ž๋™ ์ฃผ์ž… ๋ชฉ์ฐจ ์˜์กด ๊ฐ์ฒด ์ž๋™ ์ฃผ์ž… @Autowired, @Resource, @Inject ์˜์กด๊ฐ์ฒด ์„ ํƒ ์˜์กด๊ฐ์ฒด ์ž๋™ ์ฃผ์ž… ์ฒดํฌ ์˜์กด ๊ฐ์ฒด ์ž๋™ ์ฃผ์ž… ์Šคํ”„๋ง ์„ค์ • ํŒŒ์ผ์—์„œ ์˜์กด ๊ฐ์ฒด๋ฅผ ์ฃผ์ž…ํ•  ๋•Œ, ๋˜๋Š” ํƒœ๊ทธ๋กœ ์˜์กด ๋Œ€์ƒ ๊ฐ์ฒด๋ฅผ ๋ช…์‹œํ•˜์ง€ ์•Š์•„๋„ ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ž๋™์œผ๋กœ ํ•„์š”ํ•œ ์˜์กด ๋Œ€์ƒ ๊ฐ์ฒด๋ฅผ ์ฐพ์•„์„œ ์˜์กด ๋Œ€์ƒ ๊ฐ์ฒด๊ฐ€ ํ•„์š”ํ•œ ๊ฐ์ฒด์— ์ฃผ์ž…ํ•ด ์ฃผ๋Š” ๊ธฐ๋Šฅ์ด๋‹ค. @Autowired ์ฃผ์ž…ํ•˜๋ ค๊ณ  ํ•˜๋Š” ๊ฐ์ฒด์˜ ํƒ€์ž…์ด ์ผ์น˜ํ•˜๋Š” ๊ฐ์ฒด๋ฅผ ์ž๋™์œผ๋กœ ์ฃผ์ž… @Autowired๋Š” ํ•„๋“œ, ์ƒ์„ฑ์ž, Setter์— ๋ถ™์ผ ์ˆ˜ ์žˆ๋‹ค. ๋‹จ, @Autowired๋ฅผ ํ•„๋“œ, Setter์— ๋ถ™์—ฌ์„œ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ๋ฐ˜๋“œ์‹œ ๊ธฐ๋ณธ ์ƒ์„ฑ์ž๊ฐ€ ์ •์˜๋˜์–ด ์žˆ์–ด์•ผ ํ•œ๋‹ค. 1) @Autowired - ํ•„๋“œ ์ฃผ์ž… public class WordRegisterServiceUs..
DI(Dependency Injection) ๋ชฉ์ฐจ DI(Dependency Injection)๋ž€? ์Šคํ”„๋ง DI ์„ค์ • ๋ฐฉ๋ฒ• ์Šคํ”„๋ง DI ์˜ˆ์‹œ ๋‹ค์–‘ํ•œ ์˜์กด ๊ฐ์ฒด ์ฃผ์ž… ๋ฐฉ๋ฒ• DI(Dependency Injection)๋ž€? ๋‹ค์Œ ์„ธ ๊ฐ€์ง€ ๊ฒฝ์šฐ ๋‹ค DI๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‹ค๋งŒ, ์กฐ๊ธˆ์”ฉ์˜ ์ฐจ์ด๊ฐ€ ์žˆ๋‹ค. ๋ฐฐํ„ฐ๋ฆฌ ์ผ์ฒดํ˜• : ์ƒ์„ฑ์ž์—์„œ ๊ฐ์ฒด๋ฅผ ์ฃผ์ž… ๋ฐฐํ„ฐ๋ฆฌ ๋ถ„๋ฆฌํ˜•(1) : setter๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๊ฐ์ฒด๋ฅผ ์ฃผ์ž… ๋ฐฐํ„ฐ๋ฆฌ ๋ถ„๋ฆฌํ˜•(1) : ์ƒ์„ฑ์ž, setter๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๊ฐ์ฒด๋ฅผ ์ฃผ์ž… # ๋ฐฐํ„ฐ๋ฆฌ ์ผ์ฒดํ˜• public class EletronicCarToy { private Battery battery; public ElectronicCarToy() { battery = new NormalBattery(); } } # ๋ฐฐํ„ฐ๋ฆฌ ๋ถ„๋ฆฌํ˜•(1) public class EletronicR..
ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ - (๋ฐฉ๋ฒ•2)๋กœ์ปฌ์—์„œ ์ง์ ‘ ์ƒ์„ฑ ๋กœ์ปฌ์—์„œ ํด๋”(java, resources)์™€ ํŒŒ์ผ(pom.xml)์„ ์ง์ ‘ ๋งŒ๋“ค์–ด ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ• 1) ํด๋”(java, resources)์™€ "ํ”„๋กœ์ ํŠธ ํด๋” > src ํด๋” > main ํด๋” > java, resources ํด๋”" ๋ชจ๋‘ ์ƒ์„ฑ 2) ํŒŒ์ผ(pom.xml) ์ƒ์„ฑ srcํด๋”์™€ ๊ฐ™์€ ์œ„์น˜์— pom.xml ํŒŒ์ผ ์ƒ์„ฑ 4.0.0 spring4 testPjt 0.0.1-SNAPSHOT org.springframework spring-context 4.1.0.RELEASE maven-compiler-plugin 3.1 1.8 1.8 UTF-8 3) ์ดํด๋ฆฝ์Šค์—์„œ importํ•˜๊ธฐ ์ดํด๋ฆฝ์Šค์—์„œ Maven์œผ๋กœ import
๊ฐ์ฒด ์ƒ์„ฑ - (๋ฐฉ๋ฒ•2) ์ปจํ…Œ์ด๋„ˆ๋ฅผ ํ†ตํ•ด ๊ฐ์ฒด ์ƒ์„ฑ ๋ชฉ์ฐจ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ํ†ตํ•ด ๊ฐ์ฒด ์ƒ์„ฑ Bean์˜ ๋ฒ”์œ„ ์„ค์ • ํŒŒ์ผ์ด ์—ฌ๋Ÿฌ๊ฐœ์ผ ๊ฒฝ์šฐ! ์ปจํ…Œ์ด๋„ˆ๋ฅผ ํ†ตํ•ด ๊ฐ์ฒด ์ƒ์„ฑ 1) src/main/resources/applicationContext.xmlํŒŒ์ผ ์ƒ์„ฑ //bean์œผ๋กœ ๊ฐ์ฒด ์ƒ์„ฑ๋จ 2) MainClass ์ฝ”๋“œ ์ž‘์„ฑ package testPjt; import org.springframework.context.support.GenericXmlApplicationContext; public class MainClass { public static void main(String[] args) { //TransportationWalk transportationWalk = new TransportationWalk(); //transportationWalk.move(); //..
๊ฐ์ฒด ์ƒ์„ฑ - (๋ฐฉ๋ฒ•1) new์—ฐ์‚ฐ์ž๋ฅผ ์ด์šฉ new์—ฐ์‚ฐ์ž๋ฅผ ์ด์šฉํ•ด ๊ฐ์ฒด ์ƒ์„ฑ 1) ํด๋ž˜์Šค ์ƒ์„ฑ ํด๋ž˜์Šค ์ƒ์„ฑ ์™„๋ฃŒ! package testPjt; public class TransportationWalk { public void move() { System.out.println("hello"); } } 2) ๋ฉ”์ธํด๋ž˜์Šค ์ƒ์„ฑ package testPjt; public class MainClass { public static void main(String[] args) { TransportationWalk transportationWalk = new TransportationWalk(); transportationWalk.move(); } } ๊ฒฐ๊ณผ ํ™”๋ฉด!
์ž์ฃผ ์“ฐ์ด๋Š” ์ดํด๋ฆฝ์Šค ๋‹จ์ถ•ํ‚ค https://velog.io/@janeljs/eclipse-shortcuts
ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ - (๋ฐฉ๋ฒ•1)eclipse์—์„œ ์ƒ์„ฑ ๋ชฉ์ฐจ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ pom.xml ์ž‘์„ฑ ํด๋” ๋ฐ pom.xmlํŒŒ์ผ์˜ ์ดํ•ด ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ Maven์„ ์ด์šฉํ•ด์„œ ์Šคํ”„๋ง ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ ์™„๋ฃŒ! pom.xml ํŒŒ์ผ pom.xmlํŒŒ์ผ์€ Maven ์„ค์ •ํŒŒ์ผ๋กœ, Maven์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์—ฐ๊ฒฐํ•ด์ฃผ๊ณ , ๋นŒ๋“œ๋ฅผ ์œ„ํ•œ ํ”Œ๋žซํผ์ด๋‹ค. Maven์˜ ๋นŒ๋“œ ์ •๋ณด๋ฅผ ๋‹ด๊ณ ์žˆ๋Š” ํŒŒ์ผ POM(Project Object Model)์„ ์„ค์ •ํ•˜๋Š” ๋ถ€๋ถ„ ํ”„๋กœ์ ํŠธ ๋‚ด์˜ ๋นŒ๋“œ ์˜ต์…˜์„ ์„ค์ •ํ•˜๋Š” ๋ถ€๋ถ„ pom.xml ํŒŒ์ผ ์ž‘์„ฑ 4.0.0 spring4 testPjt 0.0.1-SNAPSHOT ์— ์•„๋ž˜์™€ ๊ฐ™์ด , ์ฝ”๋“œ ๋ถ€๋ถ„ ์ถ”๊ฐ€ 4.0.0 spring4 testPjt 0.0.1-SNAPSHOT org.springframework spring-context 4.1.0.RELEASE maven..
java, eclipse ์„ค์น˜ java ์„ค์น˜ ๋‹ค์Œ ์‚ฌ์ดํŠธ์—์„œ x64 Installer ๋ฅผ ํด๋ฆญํ•ด ๋‹ค์šด๋กœ๋“œ ๋ฐ›๊ธฐ https://www.oracle.com/java/technologies/downloads/#jdk19-windows Download the Latest Java LTS Free Subscribe to Java SE and get the most comprehensive Java support available, with 24/7 global access to the experts. www.oracle.com eclipse ์„ค์น˜ https://www.eclipse.org/downloads/ Eclipse Downloads | The Eclipse Foundation The Eclipse Foundation - home to ..
์Šคํ”„๋ง ์Šคํ”„๋ง ํ”„๋ ˆ์ž„์›Œํฌ ์Šคํ”„๋ง ํ”„๋ ˆ์ž„์›Œํฌ ์Šคํ”„๋ง ํ”„๋ ˆ์ž„์›Œํฌ๋Š” ์ฃผ์š”๊ธฐ๋Šฅ์œผ๋กœ DI, AOP, MVC, JDBC ๋“ฑ์„ ์ œ๊ณตํ•œ๋‹ค. ์Šคํ”„๋ง ํ”„๋ ˆ์ž„์›Œํฌ ๋ชจ๋“ˆ ์Šคํ”„๋ง ํ”„๋ ˆ์ž„์›Œํฌ์—์„œ ์ œ๊ณตํ•˜๊ณ  ์žˆ๋Š” ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด, ๋ชจ๋“ˆ์— ๋Œ€ํ•œ ์˜์กด์„ค์ •์„ ๊ฐœ๋ฐœ ํ”„๋กœ์ ํŠธ์—์„œ XMLํŒŒ์ผ๋“ค์„ ์ด์šฉํ•ด์„œ ๊ฐœ๋ฐœ์ž๊ฐ€ ์ง์ ‘ ํ•˜๋ฉด ๋œ๋‹ค. spring-core DI, IoC ์ œ๊ณต spring-aop AOP๊ตฌํ˜„ ๊ธฐ๋Šฅ ์ œ๊ณต spring-jdbc ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์‰ฝ๊ฒŒ ๋‹ค๋ฃฐ ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ ์ œ๊ณต spring-tx ์Šคํ”„๋ง์—์„œ ์ œ๊ณตํ•˜๋Š” ํŠธ๋žœ์žญ์…˜ ๊ด€๋ จ ๊ธฐ๋Šฅ ์ œ๊ณต spring-webmvc ์Šคํ”„๋ง์—์„œ ์ œ๊ณตํ•˜๋Š” Controller์™€ View๋ฅผ ์ด์šฉํ•œ MVC ๊ตฌํ˜„ ๊ธฐ๋Šฅ ์ œ๊ณต ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ(IoC) ์Šคํ”„๋ง์—์„œ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์กฐ๋ฆฝํ•˜๋Š” ์ปจํ…Œ์ด๋„ˆ๋กœ, ์ปจํ…Œ์ด๋„ˆ๋ฅผ ํ†ตํ•ด ์ƒ์„ฑ๋œ ๊ฐ์ฒด๋ฅผ ๋นˆ..