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 11package com .bobocode .config ;
22
33import com .bobocode .TestDataGenerator ;
4+ import org .springframework .context .annotation .Bean ;
5+ import org .springframework .context .annotation .ComponentScan ;
6+ import org .springframework .context .annotation .Configuration ;
47
58/**
69 * This class application context configuration.
1013 * todo: provide explicit configuration for a bean of type {@link TestDataGenerator} with name "dataGenerator" in this class.
1114 * todo: Don't specify bean name "dataGenerator" explicitly
1215 */
16+ @ Configuration
17+ @ ComponentScan (basePackages = {"com.bobocode.service" , "com.bobocode.dao" })
1318public class AppConfig {
1419
20+ @ Bean
21+ public TestDataGenerator dataGenerator () {
22+ return new TestDataGenerator ();
23+ }
1524}
Original file line number Diff line number Diff line change 33import com .bobocode .TestDataGenerator ;
44import com .bobocode .model .Account ;
55import org .springframework .beans .factory .annotation .Autowired ;
6+ import org .springframework .stereotype .Component ;
67
78import java .util .List ;
89import java .util .stream .Stream ;
1516 * todo: configure this class as Spring component with bean name "accountDao"
1617 * todo: use explicit (with {@link Autowired} annotation) constructor-based dependency injection
1718 */
19+ @ Component ("accountDao" )
1820public class FakeAccountDao implements AccountDao {
1921 private List <Account > accounts ;
2022
23+ @ Autowired
2124 public FakeAccountDao (TestDataGenerator testDataGenerator ) {
2225 this .accounts = Stream .generate (testDataGenerator ::generateAccount )
2326 .limit (20 )
Original file line number Diff line number Diff line change 22
33import com .bobocode .dao .AccountDao ;
44import com .bobocode .model .Account ;
5+ import org .springframework .stereotype .Service ;
56
67import java .util .Comparator ;
78import java .util .List ;
1213 * todo: configure {@link AccountService} bean implicitly using special annotation for service classes
1314 * todo: use implicit constructor-based dependency injection (don't use {@link org.springframework.beans.factory.annotation.Autowired})
1415 */
16+ @ Service
1517public class AccountService {
1618 private final AccountDao accountDao ;
1719
You can’t perform that action at this time.
0 commit comments