File tree Expand file tree Collapse file tree 3 files changed +14
-0
lines changed
hello-application-context/src/main/java/com/bobocode Expand file tree Collapse file tree 3 files changed +14
-0
lines changed Original file line number Diff line number Diff line change 1
1
package com .bobocode .config ;
2
2
3
3
import com .bobocode .TestDataGenerator ;
4
+ import org .springframework .context .annotation .Bean ;
5
+ import org .springframework .context .annotation .ComponentScan ;
6
+ import org .springframework .context .annotation .Configuration ;
4
7
5
8
/**
6
9
* This class application context configuration.
10
13
* todo: provide explicit configuration for a bean of type {@link TestDataGenerator} with name "dataGenerator" in this class.
11
14
* todo: Don't specify bean name "dataGenerator" explicitly
12
15
*/
16
+ @ Configuration
17
+ @ ComponentScan (basePackages = {"com.bobocode.service" , "com.bobocode.dao" })
13
18
public class AppConfig {
14
19
20
+ @ Bean
21
+ public TestDataGenerator dataGenerator () {
22
+ return new TestDataGenerator ();
23
+ }
15
24
}
Original file line number Diff line number Diff line change 3
3
import com .bobocode .TestDataGenerator ;
4
4
import com .bobocode .model .Account ;
5
5
import org .springframework .beans .factory .annotation .Autowired ;
6
+ import org .springframework .stereotype .Component ;
6
7
7
8
import java .util .List ;
8
9
import java .util .stream .Stream ;
15
16
* todo: configure this class as Spring component with bean name "accountDao"
16
17
* todo: use explicit (with {@link Autowired} annotation) constructor-based dependency injection
17
18
*/
19
+ @ Component ("accountDao" )
18
20
public class FakeAccountDao implements AccountDao {
19
21
private List <Account > accounts ;
20
22
23
+ @ Autowired
21
24
public FakeAccountDao (TestDataGenerator testDataGenerator ) {
22
25
this .accounts = Stream .generate (testDataGenerator ::generateAccount )
23
26
.limit (20 )
Original file line number Diff line number Diff line change 2
2
3
3
import com .bobocode .dao .AccountDao ;
4
4
import com .bobocode .model .Account ;
5
+ import org .springframework .stereotype .Service ;
5
6
6
7
import java .util .Comparator ;
7
8
import java .util .List ;
12
13
* todo: configure {@link AccountService} bean implicitly using special annotation for service classes
13
14
* todo: use implicit constructor-based dependency injection (don't use {@link org.springframework.beans.factory.annotation.Autowired})
14
15
*/
16
+ @ Service
15
17
public class AccountService {
16
18
private final AccountDao accountDao ;
17
19
You can’t perform that action at this time.
0 commit comments