Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Loading status checks…
Fix spring status check failed (#10534)
* fix spring status check failed Signed-off-by: crazyhzm <crazyhzm@gmail.com> * fix spring status check failed Signed-off-by: crazyhzm <crazyhzm@gmail.com> Signed-off-by: crazyhzm <crazyhzm@gmail.com>
Showing
1 changed file
with
5 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| } | |||
|
|
|||
| @Override | |||
| public Status check() { | |||
| // TODO It seems to be ok with GenericWebApplicationContext, need further confirmation | |||
| // ApplicationContext context = null; | |||
| // for (ApplicationContext c : SpringExtensionInjector.getContexts()) { | |||
| // // [Issue] SpringStatusChecker execute errors on non-XML Spring configuration | |||
| // // issue : https://github.com/apache/dubbo/issues/3615 | |||
| // if(c instanceof GenericWebApplicationContext) { // ignore GenericXmlApplicationContext | |||
| // continue; | |||
| // } | |||
| // | |||
| // if (c != null) { | |||
| // context = c; | |||
| // break; | |||
| // } | |||
| // } | |||
|
|
|||
| if (applicationContext == null && applicationModel != null) { | |||
|
|||
|
|||
| SpringExtensionInjector springExtensionInjector = SpringExtensionInjector.get(applicationModel); | |||
| applicationContext = springExtensionInjector.getContext(); | |||
| } | |||
| if (applicationContext == null) { | |||
| return new Status(Status.Level.UNKNOWN); | |||
| } | |||
| Status.Level level; | |||
| if (applicationContext instanceof Lifecycle) { | |||
| if (((Lifecycle) applicationContext).isRunning()) { | |||
| level = Status.Level.OK; | |||
| } else { | |||
| level = Status.Level.ERROR; | |||
| } | |||
| } else { | |||
| level = Status.Level.UNKNOWN; | |||
| } | |||
| StringBuilder buf = new StringBuilder(); | |||
| try { | |||
| Class<?> cls = applicationContext.getClass(); | |||
| Method method = null; | |||
| while (cls != null && method == null) { | |||
| try { | |||
| method = cls.getDeclaredMethod("getConfigLocations", new Class<?>[0]); | |||
| } catch (NoSuchMethodException t) { | |||
| cls = cls.getSuperclass(); | |||
| } | |||
| } | |||
| if (method != null) { | |||
| if (!method.isAccessible()) { | |||
| method.setAccessible(true); | |||
| } | |||
| String[] configs = (String[]) method.invoke(applicationContext, new Object[0]); | |||
| if (configs != null && configs.length > 0) { | |||
| for (String config : configs) { | |||
| if (buf.length() > 0) { | |||
| buf.append(','); | |||
| } | |||
| buf.append(config); | |||
| } | |||
| } | |||
| } | |||
| } catch (UnsupportedOperationException t) { | |||
| logger.debug(t.getMessage(), t); | |||
| } catch (Throwable t) { | |||
| logger.warn(t.getMessage(), t); | |||
| if (t.getCause() instanceof UnsupportedOperationException){ | |||
| logger.debug(t.getMessage(), t); | |||
| }else { | |||
| logger.warn(t.getMessage(), t); | |||
| } | |||
| } | |||
| return new Status(level, buf.toString()); | |||
| } | |||
| } | |||