use of org.springframework.beans.BeansException in project leopard by tanhaichao.
the class LeopardHandlerMapping method initApplicationContext.
@Override
protected void initApplicationContext() throws BeansException {
// 修改拦截器排序
try {
Field field = AbstractHandlerMapping.class.getDeclaredField("interceptors");
field.setAccessible(true);
@SuppressWarnings("unchecked") List<Object> interceptors = (List<Object>) field.get(this);
AnnotationAwareOrderComparator.sort(interceptors);
// System.out.println("interceptors:" + interceptors);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
super.initApplicationContext();
}
use of org.springframework.beans.BeansException in project leopard by tanhaichao.
the class LeopardHandlerMapping method initApplicationContext.
@Override
protected void initApplicationContext(ApplicationContext context) throws BeansException {
try {
Redis redis = (Redis) context.getBean("sessionRedis");
StoreRedisImpl.setRedis(redis);
} catch (NoSuchBeanDefinitionException e) {
logger.warn("没有配置sessionRedis,不启用分布式session.");
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
super.initApplicationContext(context);
requestMappingInfoBuilder = new RequestMappingInfoBuilderImpl(context);
}
use of org.springframework.beans.BeansException in project dubbo-faker by moyada.
the class MethodHandleProxy method getProxy.
public MethodProxy getProxy(MethodInvokeDO invokeInfo) {
// , int poolSize) {
MethodProxy proxy;
log.info("init method proxy info.");
// 检测是否已存在
Integer id = invokeInfo.getId();
SoftReference<MethodProxy> ref = proxyMap.get(id);
if (null != ref) {
proxy = ref.get();
if (null != proxy) {
// && proxy.getService().length == poolSize) {
return proxy;
}
}
// 获取参数类型
Class<?>[] paramTypes;
String[] argsType = invokeInfo.getParamType().split(",");
int length = argsType.length;
if (0 == length) {
paramTypes = new Class[0];
} else {
paramTypes = new Class[length];
for (int index = 0; index < length; index++) {
try {
paramTypes[index] = ReflectUtil.getClassType(argsType[index]);
} catch (ClassNotFoundException e) {
throw new InitializeInvokerException("获取参数类型失败: " + argsType[index]);
}
}
}
// 获取方法具柄
MethodHandle methodHandle = handle.fetchHandleInfo(invokeInfo.getClassName(), invokeInfo.getMethodName(), invokeInfo.getReturnType(), paramTypes);
// 获取接口
Class classType;
try {
classType = ReflectUtil.getClassType(invokeInfo.getClassName());
} catch (ClassNotFoundException e) {
throw new InitializeInvokerException("获取结果失败: " + invokeInfo.getClassName());
}
// 获取接口实例
Object serviceAssembly;
// Object[] serviceAssembly = new Object[poolSize];
try {
serviceAssembly = beanHolder.getBean(classType);
// for (int index = 0; index < poolSize; index++) {
// serviceAssembly[index] = beanHelper.getBean(classType);
// }
} catch (BeansException e) {
throw new RpcException("获取接口实例失败: " + invokeInfo.getClassName() + ".", e);
}
// for (Object service : serviceAssembly) {
try {
methodHandle.invoke(serviceAssembly, null);
} catch (Throwable throwable) {
}
// }
proxy = new MethodProxy();
proxy.setParamTypes(paramTypes);
proxy.setMethodHandle(methodHandle);
proxy.setService(serviceAssembly);
// 缓存调用代理
ref = new SoftReference<>(proxy);
proxyMap.put(id, ref);
return proxy;
}
use of org.springframework.beans.BeansException in project opennms by OpenNMS.
the class SnmpAssetProvisioningAdapter method doUpdateNode.
/**
* <p>doUpdate</p>
*
* @param nodeId a int.
* @param retry a boolean.
* @throws org.opennms.netmgt.provision.ProvisioningAdapterException if any.
*/
@Override
public void doUpdateNode(final int nodeId) throws ProvisioningAdapterException {
LOG.debug("doUpdate: updating nodeid: {}", nodeId);
final OnmsNode node = m_nodeDao.get(nodeId);
Assert.notNull(node, "doUpdate: failed to return node for given nodeId:" + nodeId);
final InetAddress ipaddress = m_template.execute(new TransactionCallback<InetAddress>() {
@Override
public InetAddress doInTransaction(final TransactionStatus arg0) {
return getIpForNode(node);
}
});
final String locationName = node.getLocation() != null ? node.getLocation().getLocationName() : null;
final SnmpAgentConfig agentConfig = m_snmpConfigDao.getAgentConfig(ipaddress, locationName);
final OnmsAssetRecord asset = node.getAssetRecord();
m_config.getReadLock().lock();
try {
for (AssetField field : m_config.getAssetFieldsForAddress(ipaddress, node.getSysObjectId())) {
try {
String value = fetchSnmpAssetString(m_locationAwareSnmpClient, agentConfig, locationName, field.getMibObjs(), field.getFormatString());
LOG.debug("doUpdate: Setting asset field \" {} \" to value: {}", value, field.getName());
// Use Spring bean-accessor classes to set the field value
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(asset);
try {
wrapper.setPropertyValue(field.getName(), value);
} catch (BeansException e) {
LOG.warn("doUpdate: Could not set property \" {} \" on asset object: {}", field.getName(), e.getMessage(), e);
}
} catch (Throwable t) {
// This exception is thrown if the SNMP operation fails or an incorrect number of
// parameters is returned by the agent or because of a misconfiguration.
LOG.warn("doUpdate: Could not set value for asset field \" {} \": {}", field.getName(), t.getMessage(), t);
}
}
} finally {
m_config.getReadLock().unlock();
}
node.setAssetRecord(asset);
m_nodeDao.saveOrUpdate(node);
m_nodeDao.flush();
}
use of org.springframework.beans.BeansException in project opennms by OpenNMS.
the class DefaultPluginRegistry method getPluginInstance.
/**
* {@inheritDoc}
*/
@Override
public <T> T getPluginInstance(Class<T> pluginClass, PluginConfig pluginConfig) {
T pluginInstance = beanWithNameOfType(pluginConfig.getPluginClass(), pluginClass);
if (pluginInstance == null) {
return null;
}
Map<String, String> parameters = new HashMap<String, String>(pluginConfig.getParameterMap());
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(pluginInstance);
try {
wrapper.setPropertyValues(parameters);
} catch (BeansException e) {
error(e, "Could not set properties on report definition: {}", e.getMessage());
}
return pluginInstance;
}
Aggregations