use of cn.taketoday.beans.FatalBeanException in project today-infrastructure by TAKETODAY.
the class NotConstructorBoundInjectionFailureAnalyzerTests method createFailure.
private FatalBeanException createFailure(Class<?> config) {
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
context.register(config);
context.refresh();
return null;
} catch (FatalBeanException ex) {
return ex;
}
}
use of cn.taketoday.beans.FatalBeanException in project today-framework by TAKETODAY.
the class DefaultNamespaceHandlerResolver method resolve.
/**
* Locate the {@link NamespaceHandler} for the supplied namespace URI
* from the configured mappings.
*
* @param namespaceUri the relevant namespace URI
* @return the located {@link NamespaceHandler}, or {@code null} if none found
*/
@Override
@Nullable
public NamespaceHandler resolve(String namespaceUri) {
Map<String, Object> handlerMappings = getHandlerMappings();
Object handlerOrClassName = handlerMappings.get(namespaceUri);
if (handlerOrClassName == null) {
return null;
} else if (handlerOrClassName instanceof NamespaceHandler) {
return (NamespaceHandler) handlerOrClassName;
} else {
String className = (String) handlerOrClassName;
try {
Class<NamespaceHandler> handlerClass = ClassUtils.forName(className, this.classLoader);
if (!NamespaceHandler.class.isAssignableFrom(handlerClass)) {
throw new FatalBeanException("Class [" + className + "] for namespace [" + namespaceUri + "] does not implement the [" + NamespaceHandler.class.getName() + "] interface");
}
NamespaceHandler namespaceHandler = BeanUtils.newInstance(handlerClass);
namespaceHandler.init();
handlerMappings.put(namespaceUri, namespaceHandler);
return namespaceHandler;
} catch (ClassNotFoundException ex) {
throw new FatalBeanException("Could not find NamespaceHandler class [" + className + "] for namespace [" + namespaceUri + "]", ex);
} catch (LinkageError err) {
throw new FatalBeanException("Unresolvable class definition for NamespaceHandler class [" + className + "] for namespace [" + namespaceUri + "]", err);
}
}
}
use of cn.taketoday.beans.FatalBeanException in project today-framework by TAKETODAY.
the class NotConstructorBoundInjectionFailureAnalyzerTests method createFailure.
private FatalBeanException createFailure(Class<?> config) {
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
context.register(config);
context.refresh();
return null;
} catch (FatalBeanException ex) {
return ex;
}
}
use of cn.taketoday.beans.FatalBeanException in project today-framework by TAKETODAY.
the class ServiceLocatorFactoryBeanTests method testRequiresListableBeanFactoryAndChokesOnAnythingElse.
@Test
public void testRequiresListableBeanFactoryAndChokesOnAnythingElse() throws Exception {
BeanFactory beanFactory = mock(BeanFactory.class);
try {
ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean();
factory.setBeanFactory(beanFactory);
} catch (FatalBeanException ex) {
// expected
}
}
use of cn.taketoday.beans.FatalBeanException in project today-framework by TAKETODAY.
the class NoSuchBeanDefinitionFailureAnalyzerTests method failureAnalysisForExcludedAutoConfigurationType.
@Test
void failureAnalysisForExcludedAutoConfigurationType() {
FatalBeanException failure = createFailure(StringHandler.class);
addExclusions(this.analyzer, TestPropertyAutoConfiguration.class);
FailureAnalysis analysis = analyzeFailure(failure);
assertDescriptionConstructorMissingType(analysis, StringHandler.class, 0, String.class);
String configClass = ClassUtils.getShortName(TestPropertyAutoConfiguration.class.getName());
assertClassDisabled(analysis, String.format("auto-configuration '%s' was excluded", configClass), "string", ClassUtils.getShortName(TestPropertyAutoConfiguration.class));
assertActionMissingType(analysis, String.class);
}
Aggregations