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;
}
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();
}
}
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));
}
}
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);
}
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);
}
}
Aggregations