You are currently viewing Spring Boot Masterclass – Create service and repository for Expense 06

Spring Boot Masterclass – Create service and repository for Expense 06

Hello, in this post we will create Service and Repository for Expense. Let’s begin. First, create an ExpenseRepository under src/main/java/in/bushansirgur/expenseyoutube/repository package

ExpenseRepository.java




@Repository
public interface ExpenseRepository extends JpaRepository<Expense, Long> {

}

Next, create ExpenseSerive and ExpenseServiceImpl under src/main/java/in/bushansirgur/expenseyoutube/service package

ExpenseService.java

public interface ExpenseService {
	
	List<Expense> findAll();
	
}

ExpenseServiceImpl.java

@Service
public class ExpenseServiceImpl implements ExpenseService {

	@Autowired
	ExpenseRepository expenseRepository;
	
	@Override
	public List<Expense> findAll() {
		return expenseRepository.findAll();
	}

}

That’s it for this post, let me know in the comment section if you have any questions on this.

Thanks
Bushan SC

Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

This Post Has 4 Comments

  1. ARAVIND KUAMR

    HI,
    While Fetch the Records from the Table .findAll() works until the Controller

    when I print the list in the controller it Not Display the records

    it Shows Model@56e9dc84;

    1. Bushan Sirgur

      Could you please copy my code and compare it with yours? It might be a simple typo error! Let me know the results…

  2. MD SADDAM

    hi sir i am getting error while extending JpaRepository interface.
    *************************
    APPLICATION FAILED TO START
    *************************
    Description:
    A component required a bean named ‘entityManagerFactory’ that could not be found.
    Action:

    Consider defining a bean named ‘entityManagerFactory’ in your configuration.

    Please Answer.
    I have also make a comment on video on youtube.
    Thank You.

  3. Karthik

    Hi Bushan

    When I tried to print values from expense table its printing com.one.expensemanage.model.Expense@6f432a49

Leave a Reply to Bushan Sirgur Cancel reply