use of org.springframework.beans.BeansException in project spring-framework by spring-projects.
the class WebApplicationContextFacesELResolver method getType.
@Override
public Class<?> getType(ELContext elContext, Object base, Object property) throws ELException {
if (base != null) {
if (base instanceof WebApplicationContext) {
WebApplicationContext wac = (WebApplicationContext) base;
String beanName = property.toString();
if (logger.isDebugEnabled()) {
logger.debug("Attempting to resolve property '" + beanName + "' in root WebApplicationContext");
}
if (wac.containsBean(beanName)) {
if (logger.isDebugEnabled()) {
logger.debug("Successfully resolved property '" + beanName + "' in root WebApplicationContext");
}
elContext.setPropertyResolved(true);
try {
return wac.getType(beanName);
} catch (BeansException ex) {
throw new ELException(ex);
}
} else {
// Mimic standard JSF/JSP behavior when base is a Map by returning null.
return null;
}
}
} else {
if (WEB_APPLICATION_CONTEXT_VARIABLE_NAME.equals(property)) {
elContext.setPropertyResolved(true);
return WebApplicationContext.class;
}
}
return null;
}
use of org.springframework.beans.BeansException in project spring-framework by spring-projects.
the class WebApplicationContextFacesELResolver method getValue.
@Override
public Object getValue(ELContext elContext, Object base, Object property) throws ELException {
if (base != null) {
if (base instanceof WebApplicationContext) {
WebApplicationContext wac = (WebApplicationContext) base;
String beanName = property.toString();
if (logger.isTraceEnabled()) {
logger.trace("Attempting to resolve property '" + beanName + "' in root WebApplicationContext");
}
if (wac.containsBean(beanName)) {
if (logger.isDebugEnabled()) {
logger.debug("Successfully resolved property '" + beanName + "' in root WebApplicationContext");
}
elContext.setPropertyResolved(true);
try {
return wac.getBean(beanName);
} catch (BeansException ex) {
throw new ELException(ex);
}
} else {
// Mimic standard JSF/JSP behavior when base is a Map by returning null.
return null;
}
}
} else {
if (WEB_APPLICATION_CONTEXT_VARIABLE_NAME.equals(property)) {
elContext.setPropertyResolved(true);
return getWebApplicationContext(elContext);
}
}
return null;
}
use of org.springframework.beans.BeansException in project spring-framework by spring-projects.
the class HttpServletBean method init.
/**
* Map config parameters onto bean properties of this servlet, and
* invoke subclass initialization.
* @throws ServletException if bean properties are invalid (or required
* properties are missing), or if subclass initialization fails.
*/
@Override
public final void init() throws ServletException {
if (logger.isDebugEnabled()) {
logger.debug("Initializing servlet '" + getServletName() + "'");
}
// Set bean properties from init parameters.
try {
PropertyValues pvs = new ServletConfigPropertyValues(getServletConfig(), this.requiredProperties);
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
ResourceLoader resourceLoader = new ServletContextResourceLoader(getServletContext());
bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, getEnvironment()));
initBeanWrapper(bw);
bw.setPropertyValues(pvs, true);
} catch (BeansException ex) {
if (logger.isErrorEnabled()) {
logger.error("Failed to set bean properties on servlet '" + getServletName() + "'", ex);
}
throw ex;
}
// Let subclasses do whatever initialization they like.
initServletBean();
if (logger.isDebugEnabled()) {
logger.debug("Servlet '" + getServletName() + "' configured successfully");
}
}
use of org.springframework.beans.BeansException in project spring-framework by spring-projects.
the class ConvertingEncoderDecoderSupport method getConversionService.
/**
* Strategy method used to obtain the {@link ConversionService}. By default this
* method expects a bean named {@code 'webSocketConversionService'} in the
* {@link #getApplicationContext() active ApplicationContext}.
* @return the {@link ConversionService} (never null)
*/
protected ConversionService getConversionService() {
ApplicationContext applicationContext = getApplicationContext();
Assert.state(applicationContext != null, "Unable to locate the Spring ApplicationContext");
try {
return applicationContext.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class);
} catch (BeansException ex) {
throw new IllegalStateException("Unable to find ConversionService: please configure a '" + CONVERSION_SERVICE_BEAN_NAME + "' or override the getConversionService() method", ex);
}
}
use of org.springframework.beans.BeansException in project disconf by knightliao.
the class ReloadingPropertyPlaceholderConfigurer method propertiesReloaded.
/**
* 当配置更新时,被调用
*
* @param event
*/
public void propertiesReloaded(PropertiesReloadedEvent event) {
Properties oldProperties = lastMergedProperties;
try {
//
Properties newProperties = mergeProperties();
//
// 获取哪些 dynamic property 被影响
//
Set<String> placeholders = placeholderToDynamics.keySet();
Set<DynamicProperty> allDynamics = new HashSet<DynamicProperty>();
for (String placeholder : placeholders) {
String newValue = newProperties.getProperty(placeholder);
String oldValue = oldProperties.getProperty(placeholder);
if (newValue != null && !newValue.equals(oldValue) || newValue == null && oldValue != null) {
if (logger.isInfoEnabled()) {
logger.info("Property changed detected: " + placeholder + (newValue != null ? "=" + newValue : " removed"));
}
List<DynamicProperty> affectedDynamics = placeholderToDynamics.get(placeholder);
allDynamics.addAll(affectedDynamics);
}
}
//
// 获取受影响的beans
//
Map<String, List<DynamicProperty>> dynamicsByBeanName = new HashMap<String, List<DynamicProperty>>();
Map<String, Object> beanByBeanName = new HashMap<String, Object>();
for (DynamicProperty dynamic : allDynamics) {
String beanName = dynamic.getBeanName();
List<DynamicProperty> l = dynamicsByBeanName.get(beanName);
if (l == null) {
dynamicsByBeanName.put(beanName, (l = new ArrayList<DynamicProperty>()));
Object bean = null;
try {
bean = applicationContext.getBean(beanName);
beanByBeanName.put(beanName, bean);
} catch (BeansException e) {
// keep dynamicsByBeanName list, warn only once.
logger.error("Error obtaining bean " + beanName, e);
}
//
try {
if (bean instanceof IReconfigurationAware) {
// hello!
((IReconfigurationAware) bean).beforeReconfiguration();
}
} catch (Exception e) {
logger.error("Error calling beforeReconfiguration on " + beanName, e);
}
}
l.add(dynamic);
}
//
// 处理受影响的bean
//
Collection<String> beanNames = dynamicsByBeanName.keySet();
for (String beanName : beanNames) {
Object bean = beanByBeanName.get(beanName);
if (// problems obtaining bean, earlier
bean == null) {
continue;
}
BeanWrapper beanWrapper = new BeanWrapperImpl(bean);
// for all affected ...
List<DynamicProperty> dynamics = dynamicsByBeanName.get(beanName);
for (DynamicProperty dynamic : dynamics) {
String propertyName = dynamic.getPropertyName();
String unparsedValue = dynamic.getUnparsedValue();
// obtain an updated value, including dependencies
String newValue;
removeDynamic(dynamic);
currentBeanName = beanName;
currentPropertyName = propertyName;
try {
newValue = parseStringValue(unparsedValue, newProperties, new HashSet());
} finally {
currentBeanName = null;
currentPropertyName = null;
}
if (logger.isInfoEnabled()) {
logger.info("Updating property " + beanName + "." + propertyName + " to " + newValue);
}
// assign it to the bean
try {
beanWrapper.setPropertyValue(propertyName, newValue);
} catch (BeansException e) {
logger.error("Error setting property " + beanName + "." + propertyName + " to " + newValue, e);
}
}
}
//
for (String beanName : beanNames) {
Object bean = beanByBeanName.get(beanName);
try {
if (bean instanceof IReconfigurationAware) {
((IReconfigurationAware) bean).afterReconfiguration();
}
} catch (Exception e) {
logger.error("Error calling afterReconfiguration on " + beanName, e);
}
}
} catch (IOException e) {
logger.error("Error trying to reload net.unicon.iamlabs.spring.properties.example.net.unicon.iamlabs" + ".spring" + ".properties: " + e.getMessage(), e);
}
}
Aggregations