Search in sources :

Example 56 with BeansException

use of org.springframework.beans.BeansException in project CzechIdMng by bcvsolutions.

the class SchedulerConfig method schedulerManager.

@DependsOn(CoreFlywayConfig.NAME)
@Bean(name = "schedulerManager")
public SchedulerManager schedulerManager(ApplicationContext context, IdmDependentTaskTriggerRepository dependentTaskTriggerRepository) {
    Scheduler scheduler = schedulerFactoryBean(context).getScheduler();
    SchedulerManager manager = new DefaultSchedulerManager(context, schedulerFactoryBean(context).getScheduler(), dependentTaskTriggerRepository);
    // read all task - checks obsolete task types and remove them before scheduler starts automatically
    try {
        for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(DefaultSchedulerManager.DEFAULT_GROUP_NAME))) {
            try {
                JobDetail jobDetail = scheduler.getJobDetail(jobKey);
                if (jobDetail == null) {
                    // job does not exists
                    return null;
                }
                // test task is still installed
                jobDetail.getJobClass().getDeclaredConstructor().newInstance();
            } catch (org.quartz.SchedulerException ex) {
                if (ex.getCause() instanceof ClassNotFoundException) {
                    manager.deleteTask(jobKey.getName());
                    // 
                    LOG.warn("Job [{}] inicialization failed, job class was removed, scheduled task is removed.", jobKey, ex);
                } else {
                    throw new CoreException(ex);
                }
            } catch (ReflectiveOperationException | BeansException | IllegalArgumentException ex) {
                manager.deleteTask(jobKey.getName());
                // 
                LOG.warn("Job [{}] inicialization failed, scheduled task is removed", jobKey, ex);
            }
        }
    } catch (org.quartz.SchedulerException ex) {
        throw new CoreException(ex);
    }
    // 
    return manager;
}
Also used : DefaultSchedulerManager(eu.bcvsolutions.idm.core.scheduler.service.impl.DefaultSchedulerManager) Scheduler(org.quartz.Scheduler) DefaultSchedulerManager(eu.bcvsolutions.idm.core.scheduler.service.impl.DefaultSchedulerManager) SchedulerManager(eu.bcvsolutions.idm.core.scheduler.api.service.SchedulerManager) JobKey(org.quartz.JobKey) JobDetail(org.quartz.JobDetail) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) BeansException(org.springframework.beans.BeansException) DependsOn(org.springframework.context.annotation.DependsOn) PropertiesFactoryBean(org.springframework.beans.factory.config.PropertiesFactoryBean) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 57 with BeansException

use of org.springframework.beans.BeansException in project dal by ctripcorp.

the class DalTransactionalValidatorTest method testValidatePass.

@Test
public void testValidatePass() throws InstantiationException, IllegalAccessException {
    ApplicationContext ctx;
    try {
        ctx = new ClassPathXmlApplicationContext("transactionTestByBeanDef.xml");
        TransactionAnnoClass b = ctx.getBean(TransactionAnnoClass.class);
        b.perform();
        Assert.assertNotNull(b.getTest());
        b.performOld();
    } catch (BeansException e) {
        Assert.fail();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BeansException(org.springframework.beans.BeansException) Test(org.junit.Test)

Example 58 with BeansException

use of org.springframework.beans.BeansException in project dal by ctripcorp.

the class DalTransactionalValidatorTest method testValidateFail.

@Test
public void testValidateFail() throws InstantiationException, IllegalAccessException {
    ApplicationContext ctx;
    try {
        ctx = new ClassPathXmlApplicationContext("transactionTestByBeanDefFail.xml");
        Assert.fail();
    } catch (BeansException e) {
        Assert.assertTrue(e.getMessage().contains(DalAnnotationValidator.VALIDATION_MSG));
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BeansException(org.springframework.beans.BeansException) Test(org.junit.Test)

Example 59 with BeansException

use of org.springframework.beans.BeansException in project webapp by elimu-ai.

the class EnvironmentContextLoaderListener method customizeContext.

@Override
protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext) {
    logger.info("customizeContext");
    // Load default settings
    try {
        Resource resourceConfig = new ServletContextResourceLoader(servletContext).getResource("classpath:config.properties");
        PROPERTIES.load(resourceConfig.getInputStream());
        Resource resourceJdbc = new ServletContextResourceLoader(servletContext).getResource("classpath:jdbc.properties");
        PROPERTIES.load(resourceJdbc.getInputStream());
        logger.debug("properties (before overriding): " + PROPERTIES);
    } catch (IOException ex) {
        logger.error(ex);
    }
    if ((env == Environment.TEST) || (env == Environment.PROD)) {
        InputStream inputStream = null;
        try {
            // Override config.properties
            Resource resourceConfig = new ServletContextResourceLoader(servletContext).getResource("classpath:config_" + env + ".properties");
            PROPERTIES.load(resourceConfig.getInputStream());
            // Override jdbc.properties
            Resource resourceJdbc = new ServletContextResourceLoader(servletContext).getResource("classpath:jdbc_" + env + ".properties");
            PROPERTIES.load(resourceJdbc.getInputStream());
            String contentLanguage = (String) servletContext.getAttribute("content_language");
            logger.info("contentLanguage: " + contentLanguage);
            PROPERTIES.put("content.language", contentLanguage);
            String jdbcUrl = (String) servletContext.getAttribute("jdbc_url");
            PROPERTIES.put("jdbc.url", jdbcUrl);
            String jdbcUsername = (String) servletContext.getAttribute("jdbc_username");
            PROPERTIES.put("jdbc.username", jdbcUsername);
            String jdbcPasswordAttr = (String) servletContext.getAttribute("jdbc_password");
            PROPERTIES.put("jdbc.password", jdbcPasswordAttr);
            String googleApiSecret = (String) servletContext.getAttribute("google_api_secret");
            PROPERTIES.put("google.api.secret", googleApiSecret);
            String gitHubApiSecret = (String) servletContext.getAttribute("github_api_secret");
            PROPERTIES.put("github.api.secret", gitHubApiSecret);
            String covalentApiKey = (String) servletContext.getAttribute("covalent_api_key");
            PROPERTIES.put("covalent.api.key", covalentApiKey);
            if (env == Environment.PROD) {
                String discordWebhookUrl = (String) servletContext.getAttribute("discord_webhook_url");
                PROPERTIES.put("discord.webhook.url", discordWebhookUrl);
            }
            logger.debug("properties (after overriding): " + PROPERTIES);
        } catch (FileNotFoundException ex) {
            logger.error(ex);
        } catch (IOException ex) {
            logger.error(ex);
        } finally {
            try {
                if (inputStream != null) {
                    inputStream.close();
                }
            } catch (IOException ex) {
                logger.error(ex);
            }
        }
        PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer();
        propertyPlaceholderConfigurer.setProperties(PROPERTIES);
        applicationContext.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {

            @Override
            public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
                PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer();
                propertyPlaceholderConfigurer.setProperties(PROPERTIES);
                propertyPlaceholderConfigurer.postProcessBeanFactory(configurableListableBeanFactory);
            }
        });
    }
    // Add all supported languages
    PROPERTIES.put("supported.languages", Language.values());
    // Add config properties to application scope
    servletContext.setAttribute("configProperties", PROPERTIES);
    servletContext.setAttribute("newLineCharRn", "\r\n");
    servletContext.setAttribute("newLineCharR", "\r");
    servletContext.setAttribute("newLineCharR", "\n");
    super.customizeContext(servletContext, applicationContext);
}
Also used : PropertyPlaceholderConfigurer(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) BeanFactoryPostProcessor(org.springframework.beans.factory.config.BeanFactoryPostProcessor) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) ServletContextResourceLoader(org.springframework.web.context.support.ServletContextResourceLoader) BeansException(org.springframework.beans.BeansException)

Example 60 with BeansException

use of org.springframework.beans.BeansException in project kylo by Teradata.

the class SpringContextLoaderService method loadConfiurations.

/**
 * Called by the framework to load controller configurations, this method
 * will create a spring context
 *
 * @param context not used in this case
 * @throws InitializationException an except thrown if there are any errors
 */
@OnEnabled
public void loadConfiurations(final ConfigurationContext context) throws InitializationException {
    try {
        AbstractRefreshableConfigApplicationContext appContext = new ClassPathXmlApplicationContext();
        appContext.setClassLoader(getClass().getClassLoader());
        appContext.setConfigLocation("application-context.xml");
        getLogger().info("Refreshing spring context");
        appContext.refresh();
        getLogger().info("Spring context refreshed");
        this.contextFuture.set(appContext);
    } catch (BeansException | IllegalStateException e) {
        getLogger().error("Failed to load spring configurations", e);
        throw new InitializationException(e);
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) AbstractRefreshableConfigApplicationContext(org.springframework.context.support.AbstractRefreshableConfigApplicationContext) InitializationException(org.apache.nifi.reporting.InitializationException) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) BeansException(org.springframework.beans.BeansException) OnEnabled(org.apache.nifi.annotation.lifecycle.OnEnabled)

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