/** * Gets the data source bean from the application context statically. This is needed for static @Bean creation methods that won't have access to an * auto-wired data source. * * @return the data source. */ public static DataSource getHerdDataSource() { return (DataSource) ApplicationContextHolder.getApplicationContext().getBean(HERD_DATA_SOURCE_BEAN_NAME); }
/** * Creates and returns the Spring application context. * * @return the application context */ protected ApplicationContext createApplicationContext() { // Create the Spring application context and register the JavaConfig classes we need. // We will use core (in case it's needed), the service aspect that times the duration of the service method calls, and our specific beans defined in // the data bridge configuration. We're not including full service and DAO configurations because they come with database/data source dependencies // that we don't need and don't want (i.e. we don't want the database to be running as a pre-requisite for running the uploader). AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); ApplicationContextHolder.setApplicationContext(applicationContext); applicationContext.register(CoreSpringModuleConfig.class, DataBridgeSpringModuleConfig.class, DataBridgeAopSpringModuleConfig.class, DataBridgeEnvSpringModuleConfig.class); applicationContext.refresh(); return applicationContext; } }
/** * Creates and returns the Spring application context. * * @return the application context */ private ApplicationContext createApplicationContext() { // Create the Spring application context and register the JavaConfig classes we need. // We will use core (in case it's needed), the service aspect that times the duration of the service method calls, and our specific beans defined in // the data bridge configuration. We're not including full service and DAO configurations because they come with database/data source dependencies // that we don't need and don't want (i.e. we don't want the database to be running as a pre-requisite for running the application). AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); ApplicationContextHolder.setApplicationContext(applicationContext); applicationContext.register(CoreSpringModuleConfig.class, DataBridgeSpringModuleConfig.class, DataBridgeAopSpringModuleConfig.class, DataBridgeEnvSpringModuleConfig.class); applicationContext.refresh(); return applicationContext; } }
/** * Determines whether Quartz tables need to be created which should return true for JUnits only. * * @return whether Quartz tables need to be created. */ private Boolean shouldCreateQuartzTables() { return (Boolean) ApplicationContextHolder.getApplicationContext().getBean(CREATE_QUARTZ_TABLES_BEAN_NAME); }
/** * Creates and returns the Spring application context. * * @return the application context */ protected ApplicationContext createApplicationContext() { // Create the Spring application context and register the JavaConfig classes we need. // We will use core (in case it's needed), the service aspect that times the duration of the service method calls, and our specific beans defined in // the data bridge configuration. We're not including full service and DAO configurations because they come with database/data source dependencies // that we don't need and don't want (i.e. we don't want the database to be running as a pre-requisite for running the uploader). AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); ApplicationContextHolder.setApplicationContext(applicationContext); applicationContext.register(CoreSpringModuleConfig.class, DataBridgeSpringModuleConfig.class, DataBridgeAopSpringModuleConfig.class, DataBridgeEnvSpringModuleConfig.class); applicationContext.refresh(); return applicationContext; } }
/** * Gets the data source bean from the application context statically. This is needed for static @Bean creation methods that won't have access to an * auto-wired data source. * * @return the data source. */ public static DataSource getHerdDataSource() { return (DataSource) ApplicationContextHolder.getApplicationContext().getBean(HERD_DATA_SOURCE_BEAN_NAME); }
/** * Creates and returns the Spring application context. * * @return the application context */ private ApplicationContext createApplicationContext() { // Create the Spring application context and register the JavaConfig classes we need. // We will use core (in case it's needed), the service aspect that times the duration of the service method calls, and our specific beans defined in // the data bridge configuration. We're not including full service and DAO configurations because they come with database/data source dependencies // that we don't need and don't want (i.e. we don't want the database to be running as a pre-requisite for running the application). AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); ApplicationContextHolder.setApplicationContext(applicationContext); applicationContext.register(CoreSpringModuleConfig.class, DataBridgeSpringModuleConfig.class, DataBridgeAopSpringModuleConfig.class, DataBridgeEnvSpringModuleConfig.class); applicationContext.refresh(); return applicationContext; } }
/** * Gets the Activiti database schema update param from the application context statically. * * @return the Activiti database schema update param. */ private String getActivitiDbSchemaUpdateParamBeanName() { return (String) ApplicationContextHolder.getApplicationContext().getBean(ACTIVITI_DB_SCHEMA_UPDATE_PARAM_BEAN_NAME); }
@Override protected void prepareContext(GenericApplicationContext context) { // Set the application context in the context holder for access by static @Bean methods. ApplicationContextHolder.setApplicationContext(context); // Perform standard functionality. super.prepareContext(context); } }
/** * Gets the Hibernate HBM2DDL bean from the application context statically. * * @return the Hibernate HBM2DDL auto param. */ public String getHibernateHbm2DdlAutoParam() { return (String) ApplicationContextHolder.getApplicationContext().getBean(HIBERNATE_HBM2DDL_AUTO_PARAM_BEAN_NAME); }
@Override protected void prepareContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) { // Set the application context in the context holder for access by static @Bean methods. ApplicationContextHolder.setApplicationContext(context); // Perform standard functionality. super.prepareContext(context, mergedConfig); } }
/** * Gets the Activiti database schema update param from the application context statically. * * @return the Activiti database schema update param. */ private String getActivitiDbSchemaUpdateParamBeanName() { return (String) ApplicationContextHolder.getApplicationContext().getBean(ACTIVITI_DB_SCHEMA_UPDATE_PARAM_BEAN_NAME); }
/** * Initializes the context loader listener which bootstraps Spring and provides access to the application context. * * @param servletContext the servlet context. */ protected void initContextLoaderListener(ServletContext servletContext) { // Add the context loader listener for the base (i.e. root) Spring configuration. // We register all our @Configuration annotated classes with the context so Spring will load all the @Bean's via these classes. // We also set the application context in an application context holder before "registering" so static @Bean's // (e.g. PropertySourcesPlaceholderConfigurer) will have access to it since they can't take advantage of autowiring or having a class be // ApplicationContextAware to get it. AnnotationConfigWebApplicationContext contextLoaderListenerContext = new AnnotationConfigWebApplicationContext(); ApplicationContextHolder.setApplicationContext(contextLoaderListenerContext); contextLoaderListenerContext .register(CoreSpringModuleConfig.class, DaoSpringModuleConfig.class, DaoEnvSpringModuleConfig.class, ServiceSpringModuleConfig.class, ServiceEnvSpringModuleConfig.class, UiSpringModuleConfig.class, UiEnvSpringModuleConfig.class, RestSpringModuleConfig.class, AppSpringModuleConfig.class); servletContext.addListener(new ContextLoaderListener(contextLoaderListenerContext)); }
/** * Gets the Hibernate HBM2DDL bean from the application context statically. * * @return the Hibernate HBM2DDL auto param. */ public String getHibernateHbm2DdlAutoParam() { return (String) ApplicationContextHolder.getApplicationContext().getBean(HIBERNATE_HBM2DDL_AUTO_PARAM_BEAN_NAME); }
/** * Determines whether Quartz tables need to be created which should return true for JUnits only. * * @return whether Quartz tables need to be created. */ private Boolean shouldCreateQuartzTables() { return (Boolean) ApplicationContextHolder.getApplicationContext().getBean(CREATE_QUARTZ_TABLES_BEAN_NAME); }
/** * Retrieves functional points that have no roles mapped to them. * * @return set of {@link GrantedAuthority} representing functional points */ public Set<GrantedAuthority> getUnrestrictedFunctions() { // TODO Getting HerdDao from applicationContext statically because if we try to wire HerdDao here it does not get constructed with proxy class that is // needed for @Cacheable methods to work. SecurityFunctionDao securityFunctionDao = ApplicationContextHolder.getApplicationContext().getBean(SecurityFunctionDao.class); Set<GrantedAuthority> authorities = new HashSet<>(); // Add all unrestricted functional points. for (String function : securityFunctionDao.getUnrestrictedSecurityFunctions()) { authorities.add(new SimpleGrantedAuthority(function)); } return authorities; }
SecurityFunctionDao securityFunctionDao = ApplicationContextHolder.getApplicationContext().getBean(SecurityFunctionDao.class);
/** * The data source for the application. * * @return the data source. */ @Bean public static DataSource herdDataSource() { // Access the environment using the application context holder since we're in a static method that doesn't have access to the environment in any // other way. Environment environment = ApplicationContextHolder.getApplicationContext().getEnvironment(); // Get the configuration property for the data source JNDI name. String dataSourceJndiName = ConfigurationHelper.getProperty(ConfigurationValue.HERD_DATA_SOURCE_JNDI_NAME, environment); // Return a new JNDI data source. return new JndiDataSourceLookup().getDataSource(dataSourceJndiName); }
/** * The data source for the application. * * @return the data source. */ @Bean public static DataSource herdDataSource() { // Access the environment using the application context holder since we're in a static method that doesn't have access to the environment in any // other way. Environment environment = ApplicationContextHolder.getApplicationContext().getEnvironment(); // Get the configuration property for the data source JNDI name. String dataSourceJndiName = ConfigurationHelper.getProperty(ConfigurationValue.HERD_DATA_SOURCE_JNDI_NAME, environment); // Return a new JNDI data source. return new JndiDataSourceLookup().getDataSource(dataSourceJndiName); }
JmsListenerEndpointRegistry registry = ApplicationContextHolder.getApplicationContext() .getBean("org.springframework.jms.config.internalJmsListenerEndpointRegistry", JmsListenerEndpointRegistry.class);