ืืื... ืืื ืืืืื ืืช Spring ืชืืืงืง ืืืืข ืืืืืช Java, Intellij IDEA Ultimate ืืงืฆืช ืกืืื ืืช. ืืงืืจืก ืืืืื ืืกืคืจ ืฉืืขืืจืื. ืื ืฉืืขืืจ ืืขืกืืง ืื ืืฉื ืืืจ. ืื ื ืื ืืืืืฅ ืืืื ืืืชืื ืืขืจืืช. ืื, ืืฃ ืืื ืื ืืืชื ืื ืงืจืืื ืขืืืจ ืืกืืกืืจ ืขื ืื. ืจืง ืฉืืืฉืจ ืืืชืืื ืืขืจืืช, ืื ืืืงื ืืืื ืฉื ืืขืื ืืืืืจ ืืืืข ืขืืืืื. ืืกืคืืง ืืื. ืืชืื. ืืืคืื ืฉืืืื (IoC) && ืืืจืงืช ืชืืืช (DI) ืจืืฉืืช, ืืื ื ืืืืจ ืืช ืฉื ื ืืืื ืืื ืืืฉืืืื ืืืืชืจ ืืืืคืื ืฉืืืื (IoC) ื-Dependency Injection (DI). IoC ืืื ืขืงืจืื OOP ืืืฉืืฉ ืืืคืืชืช ืฆืืืื ืืื ืืืืงืืช ืืืืืืืงืืื. ืืืชืื ืช ืืฆืื ืืช ืืงืื ืืืจืืฉ ืื ืงืืืืช ืื ืืื ืืช ืืชืืื ืืช ืืืื ื ืืืื ืืืฆื ืืืชื ืืงืื ืฉืืืฆื ืืืืจ ืืขืืื. ืืืืืื ืคืฉืืืืช, ืืขืช ืฉืืืืฉ ื-IoC, ืืงืื ืื ืืื ืขื ืืื ืืืกืืจืช ืืื ืขื ืืื ืืืชืื ืช. DI - ืืืคื ืืช ืืืืืืงืื ืืืืฉืื ืืชืืืืื ืืืฉ ืื ืืื. ืืืืืจ, ืื ืื ืื ืืืฆืื ื ืฉืคืืชื ืขื ืืื ืืืชืื ืช ืืืื ืืืชืืื ืฉื ืืืืืืงืืื. ืืขืช ืฉืืืืฉ ื-DI, ืืืชืื ืช ืืขืืื ืื ื"ืจืืช ืืืืชื" ืืื ื"ืจืืช ืืืืฉืง". ืืืจื ืื, ืชืืืช ืืื ืืืืืืงืืื ืชืืฉืืจ ืืืื ืืืื. ืืืื ื ืชืืื ืจืืฉืืช, ืืืื ื ืืฆืืจ ืคืจืืืงื ืืืืื ืคืฉืื. ืืฉื ืื, ืืืจ ืืคืจืื "ืฆืืจ ืคืจืืืงื ืืืฉ" ืืืืจ "Maven" ืืืชืคืจืื: ืืืืงืื ืื ืืชืจืื, ืชืืื ืืืฉืืืจ ืืช ืขืจืื ืืจืืจืช ืืืืื ืื ืืฉื ืืช ืืืชื ืืคื ืฉืืงืื ืืขืชื (ืืืขื ืืืจืกื): ืืืืจ ืืื ืืคืจืืืงื ืืืคืชื ืืขืจื ืขื ืืืื ื ืืื: ืืชืืงืื ืืจืืฉืืช ืืืืกื ืช ืืืืืืช ืืงืืืื ืืงืืฆืื ืืืคืขืืช ืืืืง ืืขืืงืจื ืฉื ืืชืืื ืืช. ืืืืืืช (ืืืงืจื ืฉืื ื org.example) ืืืืกื ื ืงืื Java. ืชืืงืืืช ืืืฉืืืื ืชืืื ืงืืืฆื ืชืฆืืจื ืื ืงืืฆื ืืฉืืืื. ืืชืืงืืื ืื ื ืืฆืืจ ืืช ืืงืืืฅ applicationContext.xml, ืฉืื ื ืชืืจ ืืช ืืฉืขืืขืืช ืฉืื ื (ืขืื ืขื ืื ืืืืฉื). ืชืืงืืืช ืืืืืงื ืชืืื ืฉืืขืืจื ืืืืงื. ืื ื ืืืข ืื ืืฉื ืื. ืืื ืืงืืฆืื ืืืฉืืืื ืืืืชืจ ืืื ืงืืืฅ pom.xml. ืงืืืฅ ืื ืืชืืจ ืืช ืืชืืืช ืืืืื ืขืืืจ ืืคืจืืืงื ืฉืื ื. ืขื ืืงืืืฅ ืืื ื ืชืืื ืืช ืขืืืืชื ื. ืจืืฉืืช, ืืืื ื ืคืชื ืืช ืืงืืืฅ ืืื. ืืงืืืฅ ืืืจืื ืืขืจื ืื:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>IoC</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>
ื ืืกืืฃ ืืช ืืชืืืช ืื ืืจืฉืช ืืงืืืฅ ืื. ืืฉื ืื, ืขืืืจ ืื ืืืชืจ mvnrepository.com , ืืืืื ืืช ืื ืืชืืืช ืื ืืืื ืคืจืืืงื maven. ืืืืง ืืืืคืืฉ ื ืงืืื "ืืงืฉืจ ืืืืื". ืืื ืจืฉืืืช ืืชืืฆืืืช, ืืืจ "ืืงืฉืจ ืืืืื" (ืืืืืจ "ืืงืฉืจ ืืืื" ื-apache ืืื ืืฉืื ืืืจ). ืืืืจ ืืื ืืืจ ืืช ืืืจืกื, ืจืฆืื ืืช ืืจืกืช ื-RELEASE. ืืืืจ ืืื ืืืคืชื ืืืืื ืืื: ืื ื ืืขืื ืืื ืื ืืืืง ืืืืืืฉ ืืืืื. ืืืื ื ืขืชืืง ืืช ืืงืื ืื ืืืืง ืืืชื ืืชืื ืืชื <dependencies> </dependencies>. ืื ื ืืืฆืขืื ืืช ืืืชื ืคืขืืืืช ืขืืืจ ืืชืืืช ืฉื "ืฉืขืืขืืช ืืืื" ื"ืืืืช ืืืื". ืืชืืฆืื ืืื, ืงืืืฅ pom.xml ืืืืจ ืืืืจืืืช ืื:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>IoC</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.15.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.15.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.2.15.RELEASE</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>
ืืงืฆืจื ืขื ืืื. Spring core ืืืืกื ืืช ืื ืืคืขืืืืช ืืืกืืกืืืช ืืื ืฉืืืกืืจืช ืชืขืืื. ืงืคืืฆื ืืงืฉืจ - ืืืฆืจ ืืืืืกื ืืืืืืงืื ืืืชื ืืขืืืืช DI/IoC. ืืฉืขืืขืืช ืืืื ืืฉืืฉืช ืืืฆืืจืช ืฉืขืืขืืช. ืื ื ืืกืคืจ ืื ืขื ืืคืืื ืงืฆืช ืืืืืจ ืืืชืจ. ืืืืจ ืืืกืคืช ืชืืืช, ืืืคืืข ืืืืงืื ืืคืื ื ืืฉืืืืืช ืืขืืืื ื: ืืืฅ ืขืืื ืืืืชื ืขื ืฉ-Idea ืชืืจืื ืืช ืื ืืชืืืช ืืืื. ืืืืจ ืืืืจืื, ืืชืืงืืืช ืืคืจืืืงื "ืกืคืจืืืช ืืืฆืื ืืืช" ื ืืื ืืจืืืช ืืช ืงืืฆื ื-.jar ืฉืืืจืืช ืืืืืืื ืืืกื ืชืืืช ืืืืื: ืืื ืืกืชืืื ืืฉืืขืืจ ืืจืืฉืื ืฉื ืืงืืจืก ืฉืื ื. ืื ืืืื ื ืืงืฆืจื:
- ืื ืื IoC/DI
- ืืืฆื ืืืฆืืจ ืคืจืืืงืืื ืฉื ืืืื
- ืืื ืืืืืืจ ืืืชื
GO TO FULL VERSION