Search in sources :

Example 61 with BeansException

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();
}
Also used : Field(java.lang.reflect.Field) List(java.util.List) BeansException(org.springframework.beans.BeansException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Example 62 with BeansException

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);
}
Also used : Redis(io.leopard.redis.Redis) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) BeansException(org.springframework.beans.BeansException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) RequestMappingInfoBuilderImpl(io.leopard.vhost.RequestMappingInfoBuilderImpl)

Example 63 with BeansException

use of org.springframework.beans.BeansException in project java by kubernetes-client.

the class KubernetesControllerFactory method buildController.

private Controller buildController(SharedInformerFactory sharedInformerFactory, Reconciler r) throws BeansException {
    KubernetesReconciler kubernetesReconciler = r.getClass().getAnnotation(KubernetesReconciler.class);
    String reconcilerName = kubernetesReconciler.value();
    KubernetesReconcilerWatches watches = kubernetesReconciler.watches();
    DefaultControllerBuilder builder = ControllerBuilder.defaultBuilder(sharedInformerFactory);
    RateLimitingQueue<Request> workQueue = new DefaultRateLimitingQueue<>();
    builder = builder.withWorkQueue(workQueue);
    Map<Class, AddFilterAdaptor> addFilters = getAddFilters(watches, r);
    Map<Class, UpdateFilterAdaptor> updateFilters = getUpdateFilters(watches, r);
    Map<Class, DeleteFilterAdaptor> deleteFilters = getDeleteFilters(watches, r);
    List<ReadyFuncAdaptor> readyFuncs = getReadyFuncs(r);
    for (KubernetesReconcilerWatch watch : watches.value()) {
        try {
            Function<? extends KubernetesObject, Request> workQueueKeyFunc;
            try {
                workQueueKeyFunc = watch.workQueueKeyFunc().getConstructor(WorkQueue.class).newInstance(workQueue);
            } catch (NoSuchMethodException e) {
                workQueueKeyFunc = watch.workQueueKeyFunc().newInstance();
            } catch (InvocationTargetException e) {
                throw new BeanCreationException("Failed instantiating controller watch: " + e.getMessage());
            }
            final Function<? extends KubernetesObject, Request> finalWorkQueueKeyFunc = workQueueKeyFunc;
            builder = builder.watch((q) -> {
                return ControllerBuilder.controllerWatchBuilder(watch.apiTypeClass(), q).withOnAddFilter(addFilters.get(watch.apiTypeClass())).withOnUpdateFilter(updateFilters.get(watch.apiTypeClass())).withOnDeleteFilter(deleteFilters.get(watch.apiTypeClass())).withWorkQueueKeyFunc(finalWorkQueueKeyFunc).withResyncPeriod(Duration.ofMillis(watch.resyncPeriodMillis())).build();
            });
            for (Supplier<Boolean> readyFunc : readyFuncs) {
                builder = builder.withReadyFunc(readyFunc);
            }
        } catch (IllegalAccessException | InstantiationException e) {
            throw new BeanCreationException("Failed instantiating controller: " + e.getMessage());
        }
    }
    builder = builder.withWorkerCount(kubernetesReconciler.workerCount());
    return builder.withReconciler(r).withName(reconcilerName).build();
}
Also used : WorkQueue(io.kubernetes.client.extended.workqueue.WorkQueue) AddWatchEventFilter(io.kubernetes.client.spring.extended.controller.annotation.AddWatchEventFilter) LoggerFactory(org.slf4j.LoggerFactory) KubernetesReconcilerWatch(io.kubernetes.client.spring.extended.controller.annotation.KubernetesReconcilerWatch) HashMap(java.util.HashMap) Reconciler(io.kubernetes.client.extended.controller.reconciler.Reconciler) Function(java.util.function.Function) Supplier(java.util.function.Supplier) StringUtils(org.apache.commons.lang3.StringUtils) DefaultControllerBuilder(io.kubernetes.client.extended.controller.builder.DefaultControllerBuilder) SharedInformerFactory(io.kubernetes.client.informer.SharedInformerFactory) ArrayList(java.util.ArrayList) Request(io.kubernetes.client.extended.controller.reconciler.Request) HashSet(java.util.HashSet) BiPredicate(java.util.function.BiPredicate) BeanCreationException(org.springframework.beans.factory.BeanCreationException) FactoryBean(org.springframework.beans.factory.FactoryBean) KubernetesObject(io.kubernetes.client.common.KubernetesObject) Duration(java.time.Duration) Map(java.util.Map) DeleteWatchEventFilter(io.kubernetes.client.spring.extended.controller.annotation.DeleteWatchEventFilter) DefaultRateLimitingQueue(io.kubernetes.client.extended.workqueue.DefaultRateLimitingQueue) Method(java.lang.reflect.Method) RateLimitingQueue(io.kubernetes.client.extended.workqueue.RateLimitingQueue) KubernetesReconcilerReadyFunc(io.kubernetes.client.spring.extended.controller.annotation.KubernetesReconcilerReadyFunc) KubernetesReconcilerWatches(io.kubernetes.client.spring.extended.controller.annotation.KubernetesReconcilerWatches) Logger(org.slf4j.Logger) Controller(io.kubernetes.client.extended.controller.Controller) ControllerBuilder(io.kubernetes.client.extended.controller.builder.ControllerBuilder) Predicate(java.util.function.Predicate) Set(java.util.Set) BeansException(org.springframework.beans.BeansException) KubernetesReconciler(io.kubernetes.client.spring.extended.controller.annotation.KubernetesReconciler) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) UpdateWatchEventFilter(io.kubernetes.client.spring.extended.controller.annotation.UpdateWatchEventFilter) DefaultControllerBuilder(io.kubernetes.client.extended.controller.builder.DefaultControllerBuilder) BeanCreationException(org.springframework.beans.factory.BeanCreationException) Request(io.kubernetes.client.extended.controller.reconciler.Request) DefaultRateLimitingQueue(io.kubernetes.client.extended.workqueue.DefaultRateLimitingQueue) KubernetesReconcilerWatch(io.kubernetes.client.spring.extended.controller.annotation.KubernetesReconcilerWatch) InvocationTargetException(java.lang.reflect.InvocationTargetException) KubernetesReconciler(io.kubernetes.client.spring.extended.controller.annotation.KubernetesReconciler) KubernetesReconcilerWatches(io.kubernetes.client.spring.extended.controller.annotation.KubernetesReconcilerWatches)

Example 64 with BeansException

use of org.springframework.beans.BeansException in project pmph by BCSquad.

the class PmphUserServiceImpl method getListByUsernameAndRealname.

@Override
public PageResult<PmphUserManagerVO> getListByUsernameAndRealname(String name, int number, int size) throws CheckedServiceException {
    if (null == name || "".equals(name)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "模糊查询条件为空");
    }
    List<PmphUser> pmphUsers = pmphUserDao.getListByUsernameAndRealname(name, (number - 1) * size, size);
    PageResult<PmphUserManagerVO> page = new PageResult<>();
    page.setFirst(true);
    page.setLast(true);
    page.setPageNumber(number);
    page.setPageSize(size);
    if (!pmphUsers.isEmpty()) {
        List<PmphUserManagerVO> list = new ArrayList<>();
        for (PmphUser user : pmphUsers) {
            PmphUserManagerVO userVO = new PmphUserManagerVO();
            PmphDepartment department = pmphDepartmentDao.getPmphDepartmentById(user.getDepartmentId());
            if (null != department) {
                userVO.setDepartmentName(department.getDpName());
            }
            try {
                BeanUtils.copyProperties(userVO, user);
            } catch (BeansException ex) {
                throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.VO_CONVERSION_FAILED, ex.getMessage());
            }
            list.add(userVO);
        }
        page.setRows(list);
    }
    return page;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PageResult(com.bc.pmpheep.back.plugin.PageResult) PmphDepartment(com.bc.pmpheep.back.po.PmphDepartment) BeansException(org.springframework.beans.BeansException)

Example 65 with BeansException

use of org.springframework.beans.BeansException in project pentaho-platform by pentaho.

the class SystemGwtRpcTest method testResolveTargetThrowsIfBeanResolveThrowsBeansException.

@Test(expected = GwtRpcProxyException.class)
public void testResolveTargetThrowsIfBeanResolveThrowsBeansException() {
    String servletPath = "/ws";
    String pathInfo = "/gwt/serviceName";
    String serviceKey = "ws-gwt-serviceName";
    // ---
    HttpServletRequest httpRequestMock = setupHttpRequest(servletPath, pathInfo);
    // ---
    BeansException error = mock(BeansException.class);
    ApplicationContext appContext = mock(ApplicationContext.class);
    when(appContext.containsBean(serviceKey)).thenReturn(true);
    when(appContext.getBean(serviceKey)).thenThrow(error);
    // ---
    SystemGwtRpc gwtRpc = spy(new SystemGwtRpc(httpRequestMock));
    doReturn(appContext).when(gwtRpc).createAppContext();
    // ---
    gwtRpc.resolveTarget();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ApplicationContext(org.springframework.context.ApplicationContext) BeansException(org.springframework.beans.BeansException) Test(org.junit.Test)

Aggregations

BeansException (org.springframework.beans.BeansException)126 Test (org.junit.Test)24 ApplicationContext (org.springframework.context.ApplicationContext)22 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)18 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)16 Map (java.util.Map)15 ArrayList (java.util.ArrayList)13 BeanCreationException (org.springframework.beans.factory.BeanCreationException)11 HashMap (java.util.HashMap)10 BeanWrapper (org.springframework.beans.BeanWrapper)10 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)10 MalformedURLException (java.net.MalformedURLException)9 File (java.io.File)8 IOException (java.io.IOException)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)8 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)8 List (java.util.List)7 Method (java.lang.reflect.Method)6 LinkedHashSet (java.util.LinkedHashSet)6