How to catch / fix exception in Spring ContextLoaderListener?

I use Spring ContextLoaderListener to initialize the web services client, but if the wsdl document is not available at application startup, part of my application is broken and I'm not sure how to fix it. The application starts successfully, simply registering a large stack trace of the stack at that moment. The exception is:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myWebService' defined in class path resource [spring-myapp-jaxws.xml]: Invocation of init method failed; nested exception is javax.xml.ws.WebServiceException: The following WSDL exception occurred... etc.

A couple of questions...

  • Can I catch the init exception so that I can correctly show the state of the broken component in my application?
  • Can I tell Spring to try to reinitialize myWebService bean on user request?
+3
source share
2 answers

bean lazy="true", , .

-, . :

  • java.lang.reflect.Proxy
  • CGLIB
  • Javassist
+3

:

  • javax.xml.ws.WebServiceException . , - .
  • , , -.
  • , . , - , , , (, ).

:


public interface MyWebServiceCallingInterface
{
    String callTheWebService();
}

public class MyWebService extends something, 
implements MyWebServiceCallingInterface
{
    public MyWebService()
    throws javax.xml.ws.WebServiceException
    {
        ... do stuff, maybe throw exception ...
    }

    public String callTheWebService()
    {
        ... do stuff ...
    }
}

public class MyWebServiceWrapper
implements MyWebServiceCallingInterface
{
    private MyWebService myWebService;

    public MyWebServiceWrapper()
    {
        createWebService();
    }

    public String callTheWebService()
    {
        if (myWebService == null)
        {
            createWebService();
        }

        if (myWebService != null)
        {
            return myWebService.callTheWebService();
        }
        else
        {
            ...error handling stuff...
            return ... something meaningful ...
        }

    }

    private void createWebService()
    {
        try
        {
            myWebService = new MyWebService();
        }
        catch (javax.xml.ws.webServiceException exception)
        {
            myWebService = null;
        }
    }
} 
0

Source: https://habr.com/ru/post/1761065/


All Articles