Search in sources :

Example 6 with BeanInitializationException

use of org.springframework.beans.factory.BeanInitializationException in project spring-integration by spring-projects.

the class XmppConnectionFactoryBean method start.

@Override
public void start() {
    synchronized (this.lifecycleMonitor) {
        if (this.running) {
            return;
        }
        XMPPTCPConnection connection = getConnection();
        try {
            connection.connect();
            connection.addConnectionListener(new LoggingConnectionListener());
            Roster roster = Roster.getInstanceFor(connection);
            if (this.subscriptionMode != null) {
                roster.setSubscriptionMode(this.subscriptionMode);
            } else {
                roster.setRosterLoadedAtLogin(false);
            }
            connection.login();
            this.running = true;
        } catch (Exception e) {
            throw new BeanInitializationException("failed to connect to XMPP service for " + connection.getServiceName(), e);
        }
    }
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) XMPPTCPConnection(org.jivesoftware.smack.tcp.XMPPTCPConnection) Roster(org.jivesoftware.smack.roster.Roster) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException)

Example 7 with BeanInitializationException

use of org.springframework.beans.factory.BeanInitializationException in project BroadleafCommerce by BroadleafCommerce.

the class BaseProcessor method onApplicationEvent.

/**
 * Ensures the the list of activities is properly merged and sorted after all activities have been initialized
 */
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    if (!(beanFactory instanceof ListableBeanFactory)) {
        throw new BeanInitializationException("The workflow processor [" + beanName + "] " + "is not managed by a ListableBeanFactory, please re-deploy using some derivative of ListableBeanFactory such as" + "ClassPathXmlApplicationContext ");
    }
    if (CollectionUtils.isEmpty(activities) && !isAllowEmptyActivities()) {
        throw new UnsatisfiedDependencyException(getBeanDesc(), beanName, "activities", "No activities were wired for this workflow");
    }
    // sort the activities based on their configured order
    OrderComparator.sort(activities);
    HashSet<String> moduleNames = new HashSet<>();
    for (Iterator<Activity<ProcessContext<U>>> iter = activities.iterator(); iter.hasNext(); ) {
        Activity<ProcessContext<U>> activity = iter.next();
        if (!supports(activity)) {
            throw new BeanInitializationException("The workflow processor [" + beanName + "] does " + "not support the activity of type" + activity.getClass().getName());
        }
        if (activity instanceof ModuleActivity) {
            moduleActivities.add((ModuleActivity) activity);
            moduleNames.add(((ModuleActivity) activity).getModuleName());
        }
    }
    if (CollectionUtils.isNotEmpty(moduleActivities)) {
        // log the fact that we've got some modifications to the workflow
        StringBuffer message = new StringBuffer();
        message.append("The following modules have made changes to the " + getBeanName() + " workflow: ");
        message.append(Arrays.toString(moduleNames.toArray()));
        message.append("\n");
        message.append("The final ordering of activities for the " + getBeanName() + " workflow is: \n");
        ArrayList<String> activityNames = new ArrayList<>();
        CollectionUtils.collect(activities, new Transformer() {

            @Override
            public Object transform(Object input) {
                return ((Activity) input).getBeanName();
            }
        }, activityNames);
        message.append(Arrays.toString(activityNames.toArray()));
        supportLogger.lifecycle(LifeCycleEvent.CONFIG, message.toString());
    }
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) Transformer(org.apache.commons.collections.Transformer) ArrayList(java.util.ArrayList) UnsatisfiedDependencyException(org.springframework.beans.factory.UnsatisfiedDependencyException) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) HashSet(java.util.HashSet)

Example 8 with BeanInitializationException

use of org.springframework.beans.factory.BeanInitializationException in project shiro by apache.

the class ShiroFilterFactoryBean method createInstance.

/**
 * This implementation:
 * <ol>
 * <li>Ensures the required {@link #setSecurityManager(org.apache.shiro.mgt.SecurityManager) securityManager}
 * property has been set</li>
 * <li>{@link #createFilterChainManager() Creates} a {@link FilterChainManager} instance that reflects the
 * configured {@link #setFilters(java.util.Map) filters} and
 * {@link #setFilterChainDefinitionMap(java.util.Map) filter chain definitions}</li>
 * <li>Wraps the FilterChainManager with a suitable
 * {@link org.apache.shiro.web.filter.mgt.FilterChainResolver FilterChainResolver} since the Shiro Filter
 * implementations do not know of {@code FilterChainManager}s</li>
 * <li>Sets both the {@code SecurityManager} and {@code FilterChainResolver} instances on a new Shiro Filter
 * instance and returns that filter instance.</li>
 * </ol>
 *
 * @return a new Shiro Filter reflecting any configured filters and filter chain definitions.
 * @throws Exception if there is a problem creating the AbstractShiroFilter instance.
 */
protected AbstractShiroFilter createInstance() throws Exception {
    log.debug("Creating Shiro Filter instance.");
    SecurityManager securityManager = getSecurityManager();
    if (securityManager == null) {
        String msg = "SecurityManager property must be set.";
        throw new BeanInitializationException(msg);
    }
    if (!(securityManager instanceof WebSecurityManager)) {
        String msg = "The security manager does not implement the WebSecurityManager interface.";
        throw new BeanInitializationException(msg);
    }
    FilterChainManager manager = createFilterChainManager();
    // Expose the constructed FilterChainManager by first wrapping it in a
    // FilterChainResolver implementation. The AbstractShiroFilter implementations
    // do not know about FilterChainManagers - only resolvers:
    PathMatchingFilterChainResolver chainResolver = new PathMatchingFilterChainResolver();
    chainResolver.setFilterChainManager(manager);
    // injection of the SecurityManager and FilterChainResolver:
    return new SpringShiroFilter((WebSecurityManager) securityManager, chainResolver);
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) WebSecurityManager(org.apache.shiro.web.mgt.WebSecurityManager) WebSecurityManager(org.apache.shiro.web.mgt.WebSecurityManager) SecurityManager(org.apache.shiro.mgt.SecurityManager) DefaultFilterChainManager(org.apache.shiro.web.filter.mgt.DefaultFilterChainManager) FilterChainManager(org.apache.shiro.web.filter.mgt.FilterChainManager) PathMatchingFilterChainResolver(org.apache.shiro.web.filter.mgt.PathMatchingFilterChainResolver)

Example 9 with BeanInitializationException

use of org.springframework.beans.factory.BeanInitializationException in project jim-framework by jiangmin168168.

the class BeanPostPrcessorReference method initRpcReferenceBean.

public Object initRpcReferenceBean(Object bean, String beanName) {
    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 {
                RpcReference reference = method.getAnnotation(RpcReference.class);
                if (reference != null) {
                    Object value = this.rpcClient.createProxy(method.getParameterTypes()[0], reference);
                    if (value != null) {
                        method.invoke(bean, new Object[] { value });
                    }
                }
            } catch (Exception e) {
                throw new BeanInitializationException("Failed to init remote service reference at method " + name + " in class " + bean.getClass().getName(), e);
            }
        }
    }
    Field[] fields = clazz.getDeclaredFields();
    for (Field field : fields) {
        try {
            if (!field.isAccessible()) {
                field.setAccessible(true);
            }
            RpcReference reference = field.getAnnotation(RpcReference.class);
            if (reference != null) {
                Object value = this.rpcClient.createProxy(field.getType(), reference);
                if (value != null) {
                    field.set(bean, value);
                }
            }
        } catch (Exception e) {
            throw new BeanInitializationException("Failed to init remote service reference at filed " + field.getName() + " in class " + bean.getClass().getName(), e);
        }
    }
    return bean;
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) Field(java.lang.reflect.Field) Method(java.lang.reflect.Method) BeansException(org.springframework.beans.BeansException) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) RpcReference(com.jim.framework.rpc.client.RpcReference)

Example 10 with BeanInitializationException

use of org.springframework.beans.factory.BeanInitializationException in project spring-cloud-stream by spring-cloud.

the class StreamEmitterAnnotationBeanPostProcessor method invokeSetupMethodOnToTargetChannel.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void invokeSetupMethodOnToTargetChannel(Method method, Object bean, String outboundName) {
    Object[] arguments = new Object[method.getParameterCount()];
    Object targetBean = null;
    for (int parameterIndex = 0; parameterIndex < arguments.length; parameterIndex++) {
        MethodParameter methodParameter = new SynthesizingMethodParameter(method, parameterIndex);
        Class<?> parameterType = methodParameter.getParameterType();
        Object targetReferenceValue = null;
        if (methodParameter.hasParameterAnnotation(Output.class)) {
            targetReferenceValue = AnnotationUtils.getValue(methodParameter.getParameterAnnotation(Output.class));
        } else if (arguments.length == 1 && StringUtils.hasText(outboundName)) {
            targetReferenceValue = outboundName;
        }
        if (targetReferenceValue != null) {
            targetBean = this.applicationContext.getBean((String) targetReferenceValue);
            for (StreamListenerParameterAdapter<?, Object> streamListenerParameterAdapter : this.parameterAdapters) {
                if (streamListenerParameterAdapter.supports(targetBean.getClass(), methodParameter)) {
                    arguments[parameterIndex] = streamListenerParameterAdapter.adapt(targetBean, methodParameter);
                    if (arguments[parameterIndex] instanceof FluxSender) {
                        closeableFluxResources.add((FluxSender) arguments[parameterIndex]);
                    }
                    break;
                }
            }
            Assert.notNull(arguments[parameterIndex], "Cannot convert argument " + parameterIndex + " of " + method + "from " + targetBean.getClass() + " to " + parameterType);
        } else {
            throw new IllegalStateException(StreamEmitterErrorMessages.ATLEAST_ONE_OUTPUT);
        }
    }
    Object result;
    try {
        result = method.invoke(bean, arguments);
    } catch (Exception e) {
        throw new BeanInitializationException("Cannot setup StreamEmitter for " + method, e);
    }
    if (!Void.TYPE.equals(method.getReturnType())) {
        if (targetBean == null) {
            targetBean = this.applicationContext.getBean(outboundName);
        }
        boolean streamListenerResultAdapterFound = false;
        for (StreamListenerResultAdapter streamListenerResultAdapter : this.resultAdapters) {
            if (streamListenerResultAdapter.supports(result.getClass(), targetBean.getClass())) {
                Closeable fluxDisposable = streamListenerResultAdapter.adapt(result, targetBean);
                closeableFluxResources.add(fluxDisposable);
                streamListenerResultAdapterFound = true;
                break;
            }
        }
        Assert.state(streamListenerResultAdapterFound, StreamEmitterErrorMessages.CANNOT_CONVERT_RETURN_TYPE_TO_ANY_AVAILABLE_RESULT_ADAPTERS);
    }
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) MessageChannelStreamListenerResultAdapter(org.springframework.cloud.stream.binding.MessageChannelStreamListenerResultAdapter) StreamListenerResultAdapter(org.springframework.cloud.stream.binding.StreamListenerResultAdapter) Closeable(java.io.Closeable) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) IOException(java.io.IOException) BeansException(org.springframework.beans.BeansException) MethodParameter(org.springframework.core.MethodParameter) SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter)

Aggregations

BeanInitializationException (org.springframework.beans.factory.BeanInitializationException)41 IOException (java.io.IOException)9 BeansException (org.springframework.beans.BeansException)7 HashMap (java.util.HashMap)4 Bean (org.springframework.context.annotation.Bean)4 File (java.io.File)3 Method (java.lang.reflect.Method)3 Properties (java.util.Properties)3 Field (java.lang.reflect.Field)2 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Matcher (java.util.regex.Matcher)2 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)2 PropertyValue (org.springframework.beans.PropertyValue)2 BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)2 BeanFactoryAware (org.springframework.beans.factory.BeanFactoryAware)2