March 2013
Intermediate to advanced
184 pages
4h 16m
Polish
Komponent można wstrzyknąć na poziomie pola, metody lub konstruktora za pomocą adnotacji @Inject.
Poniższy kod definiuje interfejs Greeting, obiekt POJO nazwany SimpleGreeting i implementujący ten interfejs, a także wstrzyknięcie tego interfejsu w formie pola klasy GreetingService:
public interface Greeting {
public String greet(String name);
}
public class SimpleGreeting implements Greeting {
public String greet(String name) {
return "Witaj " + name;
}
}
@Stateless
public class GreetingService {
@Inject Greeting greeting;
public String greet(String name) {
return greeting.greet(name);
}
}
Adnotacja @Inject wyznacza punkt wstrzykiwania. Interfejs Greeting określa, co ma być wstrzyknięte, a pole greeting to zmienna docelowa ...
Read now
Unlock full access