Reputation: 211
I have created a BaseRepository which extends CrudRepository
and is tagged with @NoRepositoryBean
. All my other repositories extend BaseRepository.
How can I override the save
method in my BaseRepository to have custom error messages? For example I need to catch all DataIntegrityViolationException
to show some proper message on front-end side. Any help appreciated.
UPDATE
For example, if you create Spring Endpoints (@Endpoint
) then you can create a class which implements org.springframework.ws.server.EndpointInterceptor
where you can monitor all the traffic. Is there a similar class where I can monitor all the data related traffic?
Upvotes: 0
Views: 2165
Reputation: 81970
As described in my comment overriding 'save' won't achieve your goal. JPA might throw exceptions all over your code. This is one of the problems of JPA.
I guess you could overwrite some central method of Spring to achieve your goal but that really isn't how Spring works.
In stead you basically register your exception handling so, it gets invoked by Spring as desired.
There is an article about this by Baeldung, which looks promising and is valued high by Google.
Upvotes: 1