Skip to content

Commit 874acdd

Browse files
authored
Merge pull request eugenp#5986 from codehunter34/BAEL-2399
BAEL-2399: Guice vs Spring - Dependency Injection
2 parents 46bad01 + 4375c0d commit 874acdd

24 files changed

+461
-23
lines changed

guice/pom.xml

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,45 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
<modelVersion>4.0.0</modelVersion>
5-
<groupId>com.baeldung.examples.guice</groupId>
6-
<artifactId>guice</artifactId>
7-
<version>1.0-SNAPSHOT</version>
8-
<packaging>jar</packaging>
9-
<name>guice</name>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
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+
<groupId>com.baeldung.examples.guice</groupId>
7+
<artifactId>guice</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
<name>guice</name>
1011

11-
<parent>
12-
<groupId>com.baeldung</groupId>
13-
<artifactId>parent-modules</artifactId>
14-
<version>1.0.0-SNAPSHOT</version>
15-
</parent>
12+
<parent>
13+
<groupId>com.baeldung</groupId>
14+
<artifactId>parent-modules</artifactId>
15+
<version>1.0.0-SNAPSHOT</version>
16+
</parent>
1617

17-
<dependencies>
18-
<dependency>
19-
<groupId>com.google.inject</groupId>
20-
<artifactId>guice</artifactId>
21-
<version>${guice.version}</version>
22-
</dependency>
23-
</dependencies>
18+
<dependencies>
19+
<dependency>
20+
<groupId>com.google.inject</groupId>
21+
<artifactId>guice</artifactId>
22+
<version>${guice.version}</version>
23+
</dependency>
2424

25-
<properties>
26-
<guice.version>4.1.0</guice.version>
27-
</properties>
25+
<dependency>
26+
<groupId>org.springframework</groupId>
27+
<artifactId>spring-context</artifactId>
28+
<version>${spring.version}</version>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>org.springframework</groupId>
33+
<artifactId>spring-test</artifactId>
34+
<version>${springtest.version}</version>
35+
<scope>test</scope>
36+
</dependency>
37+
</dependencies>
38+
39+
<properties>
40+
<guice.version>4.2.2</guice.version>
41+
<spring.version>5.1.3.RELEASE</spring.version>
42+
<springtest.version>5.1.3.RELEASE</springtest.version>
43+
</properties>
2844

2945
</project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.baeldung.examples.common;
2+
3+
import org.springframework.stereotype.Component;
4+
5+
@Component
6+
public class Account {
7+
8+
private String accountNumber;
9+
private String type;
10+
11+
public String getAccountNumber() {
12+
return accountNumber;
13+
}
14+
15+
public void setAccountNumber(String accountNumber) {
16+
this.accountNumber = accountNumber;
17+
}
18+
19+
public String getType() {
20+
return type;
21+
}
22+
23+
public void setType(String type) {
24+
this.type = type;
25+
}
26+
27+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.baeldung.examples.common;
2+
3+
public interface AccountService {
4+
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.baeldung.examples.common;
2+
3+
import org.springframework.stereotype.Component;
4+
5+
@Component
6+
public class AccountServiceImpl implements AccountService {
7+
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.baeldung.examples.common;
2+
3+
public interface AudioBookService {
4+
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.baeldung.examples.common;
2+
3+
public class AudioBookServiceImpl implements AudioBookService {
4+
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.baeldung.examples.common;
2+
3+
public interface AuthorService {
4+
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.baeldung.examples.common;
2+
3+
public class AuthorServiceImpl implements AuthorService {
4+
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.baeldung.examples.common;
2+
3+
public interface BookService {
4+
5+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.baeldung.examples.common;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
5+
public class BookServiceImpl implements BookService {
6+
7+
@Autowired(required = false)
8+
private AuthorService authorService;
9+
10+
}

0 commit comments

Comments
 (0)