Can I handle BeanCreationException in spring? - spring

Spring will throw BeanCreationException if there's some problem when creating a bean. If there's a way to do some thing when this exception is thrown, say, halt the process?

Related

Hazelcast throwing exception in spring boot application with vaadin 8 using openfeign

We have a web application with Vaadin 8, Spring Boot 2.1.3 and Open Feign.
Now Hazelcast should be integrated for session replication.
I was following this article.
The Problem: with Open Feign an exception is thrown in the InvocationHandler: NotSerializableException, so I implemented my own InvocationHandlerFactory setting my own InvocationHandler that is implementing the Serializable interface.
Now in the InvocationHandler the same exception is thrown:
com.hazelcast.nio.serialization.HazelcastSerializationException: Failed to serialize 'org.springframework.session.MapSession'**
com.hazelcast.nio.serialization.HazelcastSerializationException: Failed to serialize 'org.springframework.session.MapSession'
Caused by: java.io.NotSerializableException: java.lang.reflect.Method
The problem is: java.io.NotSerializableException: java.lang.reflect.Method
Method is final so it cannot be made serializable.
Is there a way to tell Hazelcast not to try to serialize certain classes?
Any workaround?
I already tried to use the ApplicationContext to avoid serialization of open feign classes but it´s not possible because the open feign clients need to be session scoped.
You are probably injecting a Feign client in a UI component, right? If so, the same happened to me when I implemented that example and I solved it by creating the Services class you can see in the article. Instead of directly injecting beans that are Feign clients or that have references to them, you can call the static methods in the Services class.

how to customized exception handler in spring boot and jersey

I use spring boot and jersey,I want to handle this exception by myself, but spring has a handle exception method. I search method to customized exception handler, but it only suitable springmvc. #ControllerAdvice only match #RequestMapping. If you know how to cancel this autoconfiguration exception handler is also useful.Thank you very very much!

spring Transaction exception handling

Basically with spring Transaction management .We can annotate the service layer class with #Transactional.
Also i have annotated my DAO layer class with #repository to make checked exception to unchecked exception.
Now when a runtimeexception is encoutered by the service layer class it will rollback.
My question how do we go about the exception handling. I will have to put some error message to UI .So i need to capture the exception .
How do i go about it.

Graceful handling of exception thrown while creating beans

I want my Spring MVC web app to gracefully handle a particular type of exception thrown while creating the beans.
The construction of one of my beans reads configuration data from an external file. If that configuration data is faulty, one of my bean constructors will throw an exception of a particular type. As the cause of the problem would be a faulty configuration file, I want my web application to respond with a useful log message and/or an error page, rather than a stack-trace of the thrown exception. So I guess I need some kind of exception handler hooked into the IOC container or dispatcher servlet. How can I do that?
Just to be clear. I'm asking about exceptions thrown as the servlet is initialising, not as it handles HTTP requests, so #ExceptionHandler annotations on controllers are not useful.
I worked around this difficulty by introducing a level of indirection. My bean is really just a handle. If the configuration file is bad, the bean catches the exception, logs a message, and notes that reading failed. Accessing the bean later then throws a suitable exception.

How to ignore Exceptions during Spring context initialization?

How to configure Spring to continue load its beans, if one of its defined beans in its init method throwed exception. lazy-init="true" option doesn't help - it is just ignored. In this bean init() method i try to open connection with server, which may fail to load the application spring context. Spring 3.0.6
The Idea of Exceptions is to fix the cause of them, not to ignore them.
Have that said: I have never seen anything for that: you have to do it by our own. Put a try catch around the init method that consume the exception and log it.
If you have real AspectJ, then you can use it for that task too. But Spring-AOP will not work.
(comment) I use side library where I should call init method, which establish connection with some server, where problem might appear.
In this case. what about a factory that provides the bean which causes the trouble to the context. The factory should check the connection first (or wait for the exception) (what exactly you do is an implementation detail) and return the bean if every thing is correct. If the connection is failing, then the factory return a Dummy implementation instead..

Resources