Section 4 Flashcards

1
Q

Ce problema rezolva Spring ?

A

In loc sa modificam codul sursa, putem schimba fisierul de configurare applicationContext.xml. Asta inseamna ca aplicatia devine configurabila ( va trebui sa inteleg chestia asta probabil printr-un exemplu )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Ce sunt Spring Beans ?

A

Spring Beans se numesc clasele create de Spring Container

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

create a Spring application using configuration file and dependenci injection ( DI )

A

//Config file

//
public interface Coach {
public String getDailyWorkout();

public String getDailyFortune();

}

//interface
public interface FortuneService {
public String getFortune();

}

//
public class HappyFortuneService implements FortuneService {
@Override
public String getFortune() {
    return "Today is your lucky day!";
}

}

//
public class BaseballCoach implements Coach {
private FortuneService fortuneService;
    public BaseballCoach(FortuneService fortuneService) {
        this.fortuneService = fortuneService;
    }
@Override
public String getDailyWorkout() {
    return "Spend 30 minutes on batting practice";
}

@Override
public String getDailyFortune() {
    return fortuneService.getFortune();
}

}

//public class HelloSpringApp {

public static void main(String[] args) {
        //load spring configuration file
        ClassPathXmlApplicationContext context
                = new ClassPathXmlApplicationContext("file:src/main/java/com/springboot/demo/applicationContext.xml");
        //retrieve bean from spring container
        Coach theCoach = context.getBean("myCoach", Coach.class);
        System.out.println(theCoach.getDailyWorkout());
    System.out.println(theCoach.getDailyFortune());
        //  close context
        context.close();
}

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Cum se numesc obiectele create de Spring Container ?

A

Spring Beans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

De ce se foloseste pattern-ul Spring?

A

Se foloseste pentru a nu fi nevoit sa modifici codul sursa, astfel se poate modifica doar fisierul de configurare.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Folosind:
- fisierul applicationContext.xml ( care se afla pe location dekstop/Udemy/Section4

  • Clasele: HelloSpringApp, TrackCoach
  1. Creati un Spring Bean
  2. Printati rezultatul metodei getDailyWorkout();
    “Run a hard 5k”
A

public class HelloSpringApp {

public static void main(String[] args) {
        //load spring configuration file - This is container
        ClassPathXmlApplicationContext context
                = new ClassPathXmlApplicationContext("file:src/main/java/com/springboot/demo/applicationContext.xml");
        //retrieve bean from spring container
        Coach myCoach = context.getBean("myCoach", Coach.class);
        System.out.println(myCoach.getDailyWorkout());
        // close context
        context.close();
    }

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly