Search⌘ K
AI Features

Develop the Business Service Tier

Explore how to develop the business service tier in Java Spring, focusing on implementing core operations like creating, finding, editing, and removing records. Learn to use services with transactional management, data access object to entity mapping, and test-driven development to ensure reliable server-side functionality.

Now it is time to look at the business service tier. We will start with the test for the finding all records operation.

Find all records operation

Java
@RunWith( SpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = { "classpath:context.xml" } )
@TransactionConfiguration( defaultRollback = true )
@Transactional
public class ProductServiceImplTest {
@Autowired
private ProductService service;
@Test
public void testFindAll() {
Assert.assertEquals(0L, service.findAll().size());
}
}

Let’s look at how to code the corresponding method in the business service. The business service corresponding Spring annotation is @Service, which is used along with the @Transactional annotation. The business service calls the data access tier. But remember that the data access tier uses entities and the business service tier uses data access objects. So, there should be a way to change ...