Close

Spring Framework - @Inject Examples

Spring Framework 

public class OrderServiceClient {

@Inject
@Qualifier("OrderServiceB")
private OrderService orderService;

public void showPendingOrderDetails() {
for (String orderId : Arrays.asList("100", "200", "300")) {
System.out.println(orderService.getOrderDetails(orderId));
}
}
}
Original Post




import javax.inject.Inject;

public class Greeter {
@Inject
private GreetingService greetingService;

public void showGreeting(String name){
System.out.println(greetingService.getGreeting(name));
}
}
Original Post




public class OrderServiceClient {

@Inject
@Named("OrderServiceB")
private OrderService orderService;

public void showPendingOrderDetails() {
for (String orderId : Arrays.asList("100", "200", "300")) {
System.out.println(orderService.getOrderDetails(orderId));
}
}
}
Original Post




import javax.inject.Inject;

public class Greeter {
private GreetingService greetingService;

@Inject
public void setGreetingService(GreetingService greetingService) {
this.greetingService = greetingService;
}

public void showGreeting(String name) {
System.out.println(greetingService.getGreeting(name));
}
}




See Also