January 2018
Intermediate to advanced
414 pages
10h 29m
English
In this book, we have used @Autowired in our examples to illustrate how we ask Spring to inject a bean into our application.
Consider this example of two services and a controller that uses them:
import org.springframework.beans.factory.annotation.Autowiredimport org.springframework.stereotype.Serviceimport org.springframework.web.bind.annotation.*@Serviceclass AccountService { fun getAccountsByCustomer(customerId: Int): List<Account> = listOf(Account(1, 125F), Account(2, 500F))}@Serviceclass CustomerService { @Autowired private lateinit var accountService: AccountService fun getCustomer(id: Int): Customer { val accounts = accountService.getAccountsByCustomer(id) return Customer(id, "customer$id", accounts) }}@RestController ...Read now
Unlock full access