use of org.springframework.context.ApplicationContext in project spring-framework by spring-projects.
the class AutoProxyLazyInitTests method withNonStaticBeanMethodAndInterface.
@Test
public void withNonStaticBeanMethodAndInterface() {
MyBeanImpl.initialized = false;
ApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithNonStaticAndInterface.class);
MyBean bean = ctx.getBean("myBean", MyBean.class);
assertFalse(MyBeanImpl.initialized);
bean.doIt();
assertTrue(MyBeanImpl.initialized);
}
use of org.springframework.context.ApplicationContext in project spring-framework by spring-projects.
the class AutoProxyLazyInitTests method withStaticBeanMethodAndInterface.
@Test
public void withStaticBeanMethodAndInterface() {
MyBeanImpl.initialized = false;
ApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithStaticAndInterface.class);
MyBean bean = ctx.getBean("myBean", MyBean.class);
assertFalse(MyBeanImpl.initialized);
bean.doIt();
assertTrue(MyBeanImpl.initialized);
}
use of org.springframework.context.ApplicationContext in project camel by apache.
the class Main method createDefaultApplicationContext.
protected AbstractApplicationContext createDefaultApplicationContext() throws IOException {
ApplicationContext parentContext = getParentApplicationContext();
// file based
if (getFileApplicationContextUri() != null) {
String[] args = getFileApplicationContextUri().split(";");
if (parentContext != null) {
return new FileSystemXmlApplicationContext(args, parentContext);
} else {
return new FileSystemXmlApplicationContext(args);
}
}
// default to classpath based
String[] args = getApplicationContextUri().split(";");
if (parentContext != null) {
return new ClassPathXmlApplicationContext(args, parentContext);
} else {
return new ClassPathXmlApplicationContext(args);
}
}
use of org.springframework.context.ApplicationContext in project spring-framework by spring-projects.
the class WebMvcConfigurationSupportTests method requestMappingHandlerAdapter.
@Test
public void requestMappingHandlerAdapter() throws Exception {
ApplicationContext context = initContext(WebConfig.class);
RequestMappingHandlerAdapter adapter = context.getBean(RequestMappingHandlerAdapter.class);
List<HttpMessageConverter<?>> converters = adapter.getMessageConverters();
assertEquals(11, converters.size());
converters.stream().filter(converter -> converter instanceof AbstractJackson2HttpMessageConverter).forEach(converter -> {
ObjectMapper mapper = ((AbstractJackson2HttpMessageConverter) converter).getObjectMapper();
assertFalse(mapper.getDeserializationConfig().isEnabled(DEFAULT_VIEW_INCLUSION));
assertFalse(mapper.getSerializationConfig().isEnabled(DEFAULT_VIEW_INCLUSION));
assertFalse(mapper.getDeserializationConfig().isEnabled(FAIL_ON_UNKNOWN_PROPERTIES));
if (converter instanceof MappingJackson2XmlHttpMessageConverter) {
assertEquals(XmlMapper.class, mapper.getClass());
}
});
ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
assertNotNull(initializer);
ConversionService conversionService = initializer.getConversionService();
assertNotNull(conversionService);
assertTrue(conversionService instanceof FormattingConversionService);
Validator validator = initializer.getValidator();
assertNotNull(validator);
assertTrue(validator instanceof LocalValidatorFactoryBean);
DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
@SuppressWarnings("unchecked") List<Object> bodyAdvice = (List<Object>) fieldAccessor.getPropertyValue("requestResponseBodyAdvice");
assertEquals(2, bodyAdvice.size());
assertEquals(JsonViewRequestBodyAdvice.class, bodyAdvice.get(0).getClass());
assertEquals(JsonViewResponseBodyAdvice.class, bodyAdvice.get(1).getClass());
}
use of org.springframework.context.ApplicationContext in project spring-framework by spring-projects.
the class WebMvcConfigurationSupportTests method mvcViewResolverWithOrderSet.
@Test
public void mvcViewResolverWithOrderSet() {
ApplicationContext context = initContext(CustomViewResolverOrderConfig.class);
ViewResolverComposite resolver = context.getBean("mvcViewResolver", ViewResolverComposite.class);
assertNotNull(resolver);
assertEquals(1, resolver.getViewResolvers().size());
assertEquals(InternalResourceViewResolver.class, resolver.getViewResolvers().get(0).getClass());
assertEquals(123, resolver.getOrder());
}
Aggregations