March 2018
Intermediate to advanced
380 pages
9h 23m
English
Since we opted to generate service classes for our entities, let's look at one. In the src/main/java/com/mycompany/store/service folder, you will find the entity repository service. Open ProductService.java:
@Service@Transactionalpublic class ProductService { private final Logger log = LoggerFactory.getLogger(ProductService.class); private final ProductRepository productRepository; public ProductService(ProductRepository productRepository) { this.productRepository = productRepository; } ...}
The service uses constructor injection to get its dependencies, which are automatically injected by Spring during bean instantiation. The service is also marked as @Transactional to enable transaction management for data access. ...