Skip to content

Commit b48d5c5

Browse files
committed
Add Lesson 6 code and Lesson6 HW
1 parent 0fb3337 commit b48d5c5

File tree

23 files changed

+685
-0
lines changed

23 files changed

+685
-0
lines changed

Lesson6.DIAppPart2/.gitignore

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Example user template template
3+
### Example user template
4+
5+
# IntelliJ project files
6+
.idea
7+
*.iml
8+
out
9+
gen### macOS template
10+
# General
11+
.DS_Store
12+
.AppleDouble
13+
.LSOverride
14+
15+
# Icon must end with two \r
16+
Icon
17+
18+
# Thumbnails
19+
._*
20+
21+
# Files that might appear in the root of a volume
22+
.DocumentRevisions-V100
23+
.fseventsd
24+
.Spotlight-V100
25+
.TemporaryItems
26+
.Trashes
27+
.VolumeIcon.icns
28+
.com.apple.timemachine.donotpresent
29+
30+
# Directories potentially created on remote AFP share
31+
.AppleDB
32+
.AppleDesktop
33+
Network Trash Folder
34+
Temporary Items
35+
.apdisk
36+
### Linux template
37+
*~
38+
39+
# temporary files which can be created if a process still has a handle open of a deleted file
40+
.fuse_hidden*
41+
42+
# KDE directory preferences
43+
.directory
44+
45+
# Linux trash folder which might appear on any partition or disk
46+
.Trash-*
47+
48+
# .nfs files are created when an open file is removed but is still being accessed
49+
.nfs*
50+
### Java template
51+
# Compiled class file
52+
*.class
53+
54+
# Log file
55+
*.log
56+
57+
# BlueJ files
58+
*.ctxt
59+
60+
# Mobile Tools for Java (J2ME)
61+
.mtj.tmp/
62+
63+
# Package Files #
64+
*.jar
65+
*.war
66+
*.nar
67+
*.ear
68+
*.zip
69+
*.tar.gz
70+
*.rar
71+
72+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
73+
hs_err_pid*
74+
### Windows template
75+
# Windows thumbnail cache files
76+
Thumbs.db
77+
ehthumbs.db
78+
ehthumbs_vista.db
79+
80+
# Dump file
81+
*.stackdump
82+
83+
# Folder config file
84+
[Dd]esktop.ini
85+
86+
# Recycle Bin used on file shares
87+
$RECYCLE.BIN/
88+
89+
# Windows Installer files
90+
*.cab
91+
*.msi
92+
*.msix
93+
*.msm
94+
*.msp
95+
96+
# Windows shortcuts
97+
*.lnk
98+
### Maven template
99+
target/
100+
pom.xml.tag
101+
pom.xml.releaseBackup
102+
pom.xml.versionsBackup
103+
pom.xml.next
104+
release.properties
105+
dependency-reduced-pom.xml
106+
buildNumber.properties
107+
.mvn/timing.properties
108+
109+
# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
110+
!/.mvn/wrapper/maven-wrapper.jar
111+

Lesson6.DIAppPart2/pom.xml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>ru.alishev.springcourse</groupId>
8+
<artifactId>FirstDIApp</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
<packaging>war</packaging>
11+
12+
<name>spring-ioc-app1 Maven Webapp</name>
13+
<!-- FIXME change it to the project's website -->
14+
<url>http://www.example.com</url>
15+
16+
<properties>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
<maven.compiler.source>1.7</maven.compiler.source>
19+
<maven.compiler.target>1.7</maven.compiler.target>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>junit</groupId>
25+
<artifactId>junit</artifactId>
26+
<version>4.11</version>
27+
<scope>test</scope>
28+
</dependency>
29+
30+
<dependency>
31+
<groupId>org.springframework</groupId>
32+
<artifactId>spring-core</artifactId>
33+
<version>5.1.4.RELEASE</version>
34+
</dependency>
35+
36+
<!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
37+
<dependency>
38+
<groupId>org.springframework</groupId>
39+
<artifactId>spring-beans</artifactId>
40+
<version>5.1.4.RELEASE</version>
41+
</dependency>
42+
43+
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
44+
<dependency>
45+
<groupId>org.springframework</groupId>
46+
<artifactId>spring-context</artifactId>
47+
<version>5.1.4.RELEASE</version>
48+
</dependency>
49+
</dependencies>
50+
51+
<build>
52+
<finalName>spring-ioc-app1</finalName>
53+
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
54+
<plugins>
55+
<plugin>
56+
<artifactId>maven-clean-plugin</artifactId>
57+
<version>3.1.0</version>
58+
</plugin>
59+
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
60+
<plugin>
61+
<artifactId>maven-resources-plugin</artifactId>
62+
<version>3.0.2</version>
63+
</plugin>
64+
<plugin>
65+
<artifactId>maven-compiler-plugin</artifactId>
66+
<version>3.8.0</version>
67+
</plugin>
68+
<plugin>
69+
<artifactId>maven-surefire-plugin</artifactId>
70+
<version>2.22.1</version>
71+
</plugin>
72+
<plugin>
73+
<artifactId>maven-war-plugin</artifactId>
74+
<version>3.2.2</version>
75+
</plugin>
76+
<plugin>
77+
<artifactId>maven-install-plugin</artifactId>
78+
<version>2.5.2</version>
79+
</plugin>
80+
<plugin>
81+
<artifactId>maven-deploy-plugin</artifactId>
82+
<version>2.8.2</version>
83+
</plugin>
84+
</plugins>
85+
</pluginManagement>
86+
</build>
87+
</project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package ru.alishev.springcourse;
2+
3+
/**
4+
* @author Neil Alishev
5+
*/
6+
public class ClassicalMusic implements Music {
7+
@Override
8+
public String getSong() {
9+
return "Hungarian Rhapsody";
10+
}
11+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package ru.alishev.springcourse;
2+
3+
/**
4+
* @author Neil Alishev
5+
*/
6+
public interface Music {
7+
String getSong();
8+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package ru.alishev.springcourse;
2+
3+
/**
4+
* @author Neil Alishev
5+
*/
6+
public class MusicPlayer {
7+
private Music music;
8+
9+
private String name;
10+
private int volume;
11+
12+
public String getName() {
13+
return name;
14+
}
15+
16+
public void setName(String name) {
17+
this.name = name;
18+
}
19+
20+
public int getVolume() {
21+
return volume;
22+
}
23+
24+
public void setVolume(int volume) {
25+
this.volume = volume;
26+
}
27+
28+
// IoC
29+
public MusicPlayer(Music music) {
30+
this.music = music;
31+
}
32+
33+
public MusicPlayer() {}
34+
35+
public void setMusic(Music music) {
36+
this.music = music;
37+
}
38+
39+
public void playMusic() {
40+
System.out.println("Playing: " + music.getSong());
41+
}
42+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package ru.alishev.springcourse;
2+
3+
/**
4+
* @author Neil Alishev
5+
*/
6+
public class RockMusic implements Music {
7+
@Override
8+
public String getSong() {
9+
return "Wind cries Mary";
10+
}
11+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ru.alishev.springcourse;
2+
3+
import org.springframework.context.support.ClassPathXmlApplicationContext;
4+
5+
/**
6+
* @author Neil Alishev
7+
*/
8+
public class TestSpring {
9+
public static void main(String[] args) {
10+
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
11+
"applicationContext.xml"
12+
);
13+
14+
// Music music = context.getBean("musicBean", Music.class);
15+
// MusicPlayer musicPlayer = new MusicPlayer(music);
16+
17+
MusicPlayer musicPlayer = context.getBean("musicPlayer", MusicPlayer.class);
18+
19+
musicPlayer.playMusic();
20+
21+
System.out.println(musicPlayer.getName());
22+
System.out.println(musicPlayer.getVolume());
23+
24+
context.close();
25+
}
26+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:context="http://www.springframework.org/schema/context"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans
6+
http://www.springframework.org/schema/beans/spring-beans.xsd
7+
http://www.springframework.org/schema/context
8+
http://www.springframework.org/schema/context/spring-context.xsd">
9+
10+
<context:property-placeholder location="classpath:musicPlayer.properties"/>
11+
12+
<bean id="musicBean"
13+
class="ru.alishev.springcourse.ClassicalMusic">
14+
</bean>
15+
16+
<bean id="musicPlayer"
17+
class="ru.alishev.springcourse.MusicPlayer">
18+
<property name="music" ref="musicBean"/>
19+
20+
<property name="name" value="${musicPlayer.name}"/>
21+
<property name="volume" value="${musicPlayer.volume}"/>
22+
</bean>
23+
24+
</beans>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
musicPlayer.name=Some name
2+
musicPlayer.volume=70
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!DOCTYPE web-app PUBLIC
2+
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
3+
"http://java.sun.com/dtd/web-app_2_3.dtd" >
4+
5+
<web-app>
6+
<display-name>Archetype Created Web Application</display-name>
7+
</web-app>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<body>
3+
<h2>Hello World!</h2>
4+
</body>
5+
</html>

0 commit comments

Comments
 (0)