use of org.springframework.beans.factory.BeanCreationException in project spring-framework by spring-projects.
the class XmlBeanFactoryTests method defaultLazyInit.
@Test
void defaultLazyInit() {
InitAndIB.constructed = false;
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(DEFAULT_LAZY_CONTEXT);
assertThat(InitAndIB.constructed).isFalse();
xbf.preInstantiateSingletons();
assertThat(InitAndIB.constructed).isTrue();
try {
xbf.getBean("lazy-and-bad");
} catch (BeanCreationException ex) {
assertThat(ex.getCause() instanceof IOException).isTrue();
}
}
use of org.springframework.beans.factory.BeanCreationException in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method responseBodyArgMismatch.
@PathPatternsParameterizedTest
void responseBodyArgMismatch(boolean usePathPatterns) throws Exception {
initDispatcherServlet(RequestBodyArgMismatchController.class, usePathPatterns, wac -> {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(A.class, B.class);
try {
marshaller.afterPropertiesSet();
} catch (Exception ex) {
throw new BeanCreationException(ex.getMessage(), ex);
}
MarshallingHttpMessageConverter messageConverter = new MarshallingHttpMessageConverter(marshaller);
RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
adapterDef.getPropertyValues().add("messageConverters", messageConverter);
wac.registerBeanDefinition("handlerAdapter", adapterDef);
});
MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/something");
String requestBody = "<b/>";
request.setContent(requestBody.getBytes(StandardCharsets.UTF_8));
request.addHeader("Content-Type", "application/xml; charset=utf-8");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getStatus()).isEqualTo(400);
}
use of org.springframework.beans.factory.BeanCreationException in project spring-framework by spring-projects.
the class ContextLoaderTests method singletonDestructionOnStartupFailure.
@Test
@SuppressWarnings("resource")
void singletonDestructionOnStartupFailure() throws IOException {
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> new ClassPathXmlApplicationContext(new String[] { "/org/springframework/web/context/WEB-INF/applicationContext.xml", "/org/springframework/web/context/WEB-INF/fail.xml" }) {
@Override
public void refresh() throws BeansException {
try {
super.refresh();
} catch (BeanCreationException ex) {
DefaultListableBeanFactory factory = (DefaultListableBeanFactory) getBeanFactory();
assertThat(factory.getSingletonCount()).isEqualTo(0);
throw ex;
}
}
});
}
use of org.springframework.beans.factory.BeanCreationException in project dhis2-core by dhis2.
the class DefaultTrackerPreheatServiceTest method shouldDoNothingWhenSupplierBeanNotFound.
@Test
void shouldDoNothingWhenSupplierBeanNotFound() {
when(applicationContext.getBean(bean.capture(), preheatSupplierClassCaptor.capture())).thenThrow(new BeanCreationException("e"));
preheatService.preheat(preheatParams);
verify(applicationContext).getBean(bean.getValue(), preheatSupplierClassCaptor.getValue());
verify(classBasedSupplier, times(0)).add(any(), any());
verify(classBasedSupplier, times(0)).preheatAdd(any(), any());
}
use of org.springframework.beans.factory.BeanCreationException in project spring-cloud-connectors by spring-cloud.
the class CloudServiceIntroducer method postProcessBeanFactory.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
try {
Constructor<?> ctor = serviceConnectorFactoryType.getConstructor(String.class, ServiceConnectorConfig.class);
AbstractCloudServiceConnectorFactory<?> serviceFactory = (AbstractCloudServiceConnectorFactory<?>) ctor.newInstance(serviceId, serviceConnectorConfig);
serviceFactory.setServiceConnectorType((Class) serviceConnectorType);
serviceFactory.setBeanFactory(beanFactory);
serviceFactory.afterPropertiesSet();
// id is the beanId if specified, otherwise the serviceId
if (StringUtils.hasText(beanId)) {
beanFactory.registerSingleton(beanId, serviceFactory);
} else {
beanFactory.registerSingleton(serviceFactory.getServiceId(), serviceFactory);
}
} catch (Exception ex) {
throw new BeanCreationException("Error registering service factory", ex);
}
}
Aggregations