Java Code Examples for org.springframework.context.ConfigurableApplicationContext#containsBean()
The following examples show how to use
org.springframework.context.ConfigurableApplicationContext#containsBean() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataSourceService.java From mapper-generator-javafx with Apache License 2.0 | 5 votes |
/** * 注册dataSource至Spring * * @param dataSource 数据源信息 */ private void addDataSourceToSpring(DataSource dataSource) { ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) this.applicationContext; HikariDataSource hikariDataSource = new HikariDataSource(); hikariDataSource.setUsername(dataSource.getUser()); hikariDataSource.setPassword(dataSource.getPassword()); hikariDataSource.setJdbcUrl("jdbc:mysql://" + dataSource.getHost() + ":" + dataSource.getPort() + "/" + dataSource.getDatabase() + "?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=CTT"); hikariDataSource.setDriverClassName(dataSource.getDriveName()); JdbcTemplate jdbcTemplate = new JdbcTemplate(hikariDataSource); if (!applicationContext.containsBean(dataSource.toString())) { applicationContext.getBeanFactory().registerSingleton(dataSource.toString(), jdbcTemplate); } }
Example 2
Source File: ActionServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Loads this executor into the ApplicationContext, if it isn't already there */ public static void registerIfNeeded(ConfigurableApplicationContext ctx) { if (!ctx.containsBean(TransientFailActionExecuter.NAME)) { // Create, and do dependencies TransientFailActionExecuter executor = new TransientFailActionExecuter(); executor.setTrackStatus(true); executor.actionTrackingService = (ActionTrackingService) ctx.getBean("actionTrackingService"); // Register ctx.getBeanFactory().registerSingleton(TransientFailActionExecuter.NAME, executor); } }
Example 3
Source File: FunctionConfiguration.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
@Bean public InitializingBean functionInitializer(FunctionCatalog functionCatalog, FunctionInspector functionInspector, StreamFunctionProperties functionProperties, @Nullable BindableProxyFactory[] bindableProxyFactories, BindingServiceProperties serviceProperties, ConfigurableApplicationContext applicationContext, FunctionBindingRegistrar bindingHolder, StreamBridge streamBridge) { boolean shouldCreateInitializer = applicationContext.containsBean("output") || ObjectUtils.isEmpty(applicationContext.getBeanNamesForAnnotation(EnableBinding.class)); return shouldCreateInitializer ? new FunctionToDestinationBinder(functionCatalog, functionProperties, serviceProperties, streamBridge) : null; }
Example 4
Source File: WebContext.java From Milkomeda with MIT License | 3 votes |
/** * 动态注册并返回bean * @param applicationContext 应用上下文 * @param name bean name * @param clazz bean class * @param args 构造参数 * @param <T> 实体类型 * @return Bean */ public static <T> T registerBean(ConfigurableApplicationContext applicationContext, String name, Class<T> clazz, Object... args) { if (applicationContext.containsBean(name)) { return applicationContext.getBean(name, clazz); } BeanDefinition beanDefinition = build(clazz, args); return registerBean(applicationContext, name, clazz, beanDefinition); }