What's the difference between @Component, @Repository & @Service annotations in Spring?

后端 未结 29 2209
时光说笑
时光说笑 2020-11-22 00:33

Can @Component, @Repository and @Service annotations be used interchangeably in Spring or do they provide any particular functionality besides acting as a notation device?

29条回答
  •  一整个雨季
    2020-11-22 00:46

    Use of @Service and @Repository annotations are important from database connection perspective.

    1. Use @Service for all your web service type of DB connections
    2. Use @Repository for all your stored proc DB connections

    If you do not use the proper annotations, you may face commit exceptions overridden by rollback transactions. You will see exceptions during stress load test that is related to roll back JDBC transactions.

提交回复
热议问题