use of org.springframework.beans.factory.BeanInitializationException in project OpenClinica by OpenClinica.
the class QueryStore method init.
public void init() {
String dbFolder = resolveDbFolder();
PathMatchingResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(resourceLoader);
try {
Resource[] resources = resourceResolver.getResources("classpath:queries/" + dbFolder + "/**/*.properties");
for (Resource r : resources) {
Properties p = new Properties();
p.load(r.getInputStream());
fileByName.put(StringUtils.substringBeforeLast(r.getFilename(), "."), p);
}
} catch (IOException e) {
throw new BeanInitializationException("Unable to read files from directory 'classpath:queries/" + dbFolder + "'", e);
}
}
use of org.springframework.beans.factory.BeanInitializationException in project motan by weibocom.
the class AnnotationBean method postProcessBeforeInitialization.
/**
* init reference field
*
* @param bean
* @param beanName
* @return
* @throws BeansException
*/
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (!isMatchPackage(bean)) {
return bean;
}
Class<?> clazz = bean.getClass();
if (isProxyBean(bean)) {
clazz = AopUtils.getTargetClass(bean);
}
Method[] methods = clazz.getMethods();
for (Method method : methods) {
String name = method.getName();
if (name.length() > 3 && name.startsWith("set") && method.getParameterTypes().length == 1 && Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers())) {
try {
MotanReferer reference = method.getAnnotation(MotanReferer.class);
if (reference != null) {
Object value = refer(reference, method.getParameterTypes()[0]);
if (value != null) {
method.invoke(bean, new Object[] { value });
}
}
} catch (Throwable t) {
throw new BeanInitializationException("Failed to init remote service reference at method " + name + " in class " + bean.getClass().getName(), t);
}
}
}
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
try {
if (!field.isAccessible()) {
field.setAccessible(true);
}
MotanReferer reference = field.getAnnotation(MotanReferer.class);
if (reference != null) {
Object value = refer(reference, field.getType());
if (value != null) {
field.set(bean, value);
}
}
} catch (Throwable t) {
throw new BeanInitializationException("Failed to init remote service reference at filed " + field.getName() + " in class " + bean.getClass().getName(), t);
}
}
return bean;
}
use of org.springframework.beans.factory.BeanInitializationException in project midpoint by Evolveum.
the class TestSqlRepositoryBeanPostProcessor method postProcessAfterInitialization.
@Override
public Object postProcessAfterInitialization(@NotNull Object bean, @NotNull String beanName) throws BeansException {
if (!(bean instanceof SessionFactory)) {
return bean;
}
LOGGER.info("Postprocessing session factory - removing everything from database if necessary.");
// we'll attempt to drop database objects if configuration contains dropIfExists=true and embedded=false
if (!repoConfig.isDropIfExists() || repoConfig.isEmbedded()) {
LOGGER.info("We're not deleting objects from DB, drop if exists=false or embedded=true.");
return bean;
}
LOGGER.info("Deleting objects from database.");
SessionFactory sessionFactory = (SessionFactory) bean;
Session session = sessionFactory.openSession();
try {
session.beginTransaction();
Query<?> query;
if (useProcedure(repoConfig)) {
LOGGER.info("Using truncate procedure.");
query = session.createNativeQuery("{ call " + TRUNCATE_PROCEDURE + "() }");
query.executeUpdate();
} else {
LOGGER.info("Using truncate function.");
query = session.createNativeQuery("select " + TRUNCATE_FUNCTION + "();");
query.uniqueResult();
}
session.getTransaction().commit();
} catch (Exception ex) {
LOGGER.error("Couldn't cleanup database, reason: " + ex.getMessage(), ex);
if (session != null && session.isOpen()) {
Transaction transaction = session.getTransaction();
if (transaction != null && transaction.isActive()) {
transaction.rollback();
}
}
throw new BeanInitializationException("Couldn't cleanup database, reason: " + ex.getMessage(), ex);
} finally {
if (session != null && session.isOpen()) {
session.close();
}
}
return bean;
}
use of org.springframework.beans.factory.BeanInitializationException in project spring-framework by spring-projects.
the class EventListenerMethodProcessor method afterSingletonsInstantiated.
@Override
public void afterSingletonsInstantiated() {
ConfigurableListableBeanFactory beanFactory = this.beanFactory;
Assert.state(this.beanFactory != null, "No ConfigurableListableBeanFactory set");
String[] beanNames = beanFactory.getBeanNamesForType(Object.class);
for (String beanName : beanNames) {
if (!ScopedProxyUtils.isScopedTarget(beanName)) {
Class<?> type = null;
try {
type = AutoProxyUtils.determineTargetClass(beanFactory, beanName);
} catch (Throwable ex) {
// An unresolvable bean type, probably from a lazy bean - let's ignore it.
if (logger.isDebugEnabled()) {
logger.debug("Could not resolve target class for bean with name '" + beanName + "'", ex);
}
}
if (type != null) {
if (ScopedObject.class.isAssignableFrom(type)) {
try {
Class<?> targetClass = AutoProxyUtils.determineTargetClass(beanFactory, ScopedProxyUtils.getTargetBeanName(beanName));
if (targetClass != null) {
type = targetClass;
}
} catch (Throwable ex) {
// An invalid scoped proxy arrangement - let's ignore it.
if (logger.isDebugEnabled()) {
logger.debug("Could not resolve target bean for scoped proxy '" + beanName + "'", ex);
}
}
}
try {
processBean(beanName, type);
} catch (Throwable ex) {
throw new BeanInitializationException("Failed to process @EventListener " + "annotation on bean with name '" + beanName + "'", ex);
}
}
}
}
}
use of org.springframework.beans.factory.BeanInitializationException in project spring-framework by spring-projects.
the class PropertyResourceConfigurer method postProcessBeanFactory.
/**
* {@linkplain #mergeProperties Merge}, {@linkplain #convertProperties convert} and
* {@linkplain #processProperties process} properties against the given bean factory.
* @throws BeanInitializationException if any properties cannot be loaded
*/
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
try {
Properties mergedProps = mergeProperties();
// Convert the merged properties, if necessary.
convertProperties(mergedProps);
// Let the subclass process the properties.
processProperties(beanFactory, mergedProps);
} catch (IOException ex) {
throw new BeanInitializationException("Could not load properties", ex);
}
}
Aggregations