@Bean @DependsOn("liquibase") public MultiTenantSpringLiquibase multiTenantLiquibase( DataSource dataSource, LiquibaseProperties liquibaseProperties) { MultiTenantSpringLiquibase liquibase = new XmMultiTenantSpringLiquibase(); liquibase.setDataSource(dataSource); liquibase.setChangeLog(CHANGE_LOG_PATH); liquibase.setContexts(liquibaseProperties.getContexts()); liquibase.setDefaultSchema(liquibaseProperties.getDefaultSchema()); liquibase.setDropFirst(liquibaseProperties.isDropFirst()); liquibase.setSchemas(getSchemas()); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_NO_LIQUIBASE)) { liquibase.setShouldRun(false); } else { liquibase.setShouldRun(liquibaseProperties.isEnabled()); log.debug("Configuring Liquibase"); } liquibase.setParameters(DatabaseUtil.defaultParams(liquibaseProperties.getDefaultSchema())); return liquibase; }
@Bean @DependsOn("liquibase") public MultiTenantSpringLiquibase multiTenantLiquibase( DataSource dataSource, LiquibaseProperties liquibaseProperties) { MultiTenantSpringLiquibase liquibase = new XmMultiTenantSpringLiquibase(); liquibase.setDataSource(dataSource); liquibase.setChangeLog(CHANGE_LOG_PATH); liquibase.setContexts(liquibaseProperties.getContexts()); liquibase.setDefaultSchema(liquibaseProperties.getDefaultSchema()); liquibase.setDropFirst(liquibaseProperties.isDropFirst()); liquibase.setSchemas(getSchemas()); if (env.acceptsProfiles(JHipsterConstants.SPRING_PROFILE_NO_LIQUIBASE)) { liquibase.setShouldRun(false); } else { liquibase.setShouldRun(liquibaseProperties.isEnabled()); log.debug("Configuring Liquibase"); } return liquibase; }
@Bean(initMethod = "block") @DependsOn("cloudFoundryCleaner") Mono<String> organizationId(CloudFoundryClient cloudFoundryClient, String organizationName) throws InterruptedException { return PaginationUtils .requestClientV2Resources(page -> cloudFoundryClient.organizations() .list(ListOrganizationsRequest.builder() .name(organizationName) .page(page) .build())) .map(ResourceUtils::getId) .single() .doOnSubscribe(s -> this.logger.debug(">> ORGANIZATION name({}) <<", organizationName)) .doOnError(Throwable::printStackTrace) .doOnSuccess(id -> this.logger.debug("<< ORGANIZATION id({}) >>", id)) .cache(); }
@Bean(initMethod = "block") @DependsOn("cloudFoundryCleaner") Mono<String> spaceId(CloudFoundryClient cloudFoundryClient, Mono<String> organizationId, String spaceName, String userName) throws InterruptedException { return organizationId .then(orgId -> cloudFoundryClient.spaces() .create(CreateSpaceRequest.builder() .name(spaceName) .organizationId(orgId) .build())) .map(ResourceUtils::getId) .as(thenKeep(spaceId1 -> cloudFoundryClient.spaces() .associateDeveloperByUsername(AssociateSpaceDeveloperByUsernameRequest.builder() .username(userName) .spaceId(spaceId1) .build()))) .doOnSubscribe(s -> this.logger.debug(">> SPACE name({}) <<", spaceName)) .doOnError(Throwable::printStackTrace) .doOnSuccess(id -> this.logger.debug("<< SPACE id({}) >>", id)) .cache(); }
@Bean(name = "shiroFilter") @DependsOn("securityManager") @ConditionalOnMissingBean public ShiroFilterFactoryBean getShiroFilterFactoryBean(DefaultSecurityManager securityManager, Realm realm, ShiroFilterRegistry registry) { securityManager.setRealm(realm); Map<String, String> filterDef = swapKeyValue(properties.getFilterChainDefinitions()); log.info("过虑器配置: {}", filterDef); log.info("自定义过虑器: {}", registry.getFilterMap()); ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean(); shiroFilter.setSecurityManager(securityManager); shiroFilter.setLoginUrl(properties.getLoginUrl()); shiroFilter.setSuccessUrl(properties.getSuccessUrl()); shiroFilter.setUnauthorizedUrl(properties.getUnauthorizedUrl()); shiroFilter.setFilterChainDefinitionMap(filterDef); shiroFilter.getFilters().putAll(registry.getFilterMap()); return shiroFilter; }
@Bean(name = "mainRealm") @ConditionalOnMissingBean(name = "mainRealm") @ConditionalOnProperty(prefix = "shiro.realm.jdbc", name = "enabled", havingValue = "true") @DependsOn(value = {"dataSource", "lifecycleBeanPostProcessor", "credentialsMatcher"}) public Realm jdbcRealm(DataSource dataSource, CredentialsMatcher credentialsMatcher) { JdbcRealm realm = new JdbcRealm(); if (shiroJdbcRealmProperties.getAuthenticationQuery() != null) { realm.setAuthenticationQuery(shiroJdbcRealmProperties.getAuthenticationQuery()); } if (shiroJdbcRealmProperties.getUserRolesQuery() != null) { realm.setUserRolesQuery(shiroJdbcRealmProperties.getUserRolesQuery()); } if (shiroJdbcRealmProperties.getPermissionsQuery() != null) { realm.setPermissionsQuery(shiroJdbcRealmProperties.getPermissionsQuery()); } if (shiroJdbcRealmProperties.getSalt() != null) { realm.setSaltStyle(shiroJdbcRealmProperties.getSalt()); } realm.setPermissionsLookupEnabled(shiroJdbcRealmProperties.isPermissionsLookupEnabled()); realm.setDataSource(dataSource); realm.setCredentialsMatcher(credentialsMatcher); return realm; }
@Bean @DependsOn("cxf") public Server jaxRsServer() { JAXRSServerFactoryBean serverFactory = RuntimeDelegate.getInstance().createEndpoint(jaxRsApiApplication(), JAXRSServerFactoryBean.class); //factory.setServiceBean(new DenialCategoryRest()); // get all the class annotated with @JaxrsService List<Object> beans = configUtil.findBeans( JaxrsService.class ); if (beans.size() > 0) { // add all the CXF service classes into the CXF stack serverFactory.setServiceBeans( beans ); serverFactory.setAddress("/"+ serverFactory.getAddress()); serverFactory.setBus(springBus); serverFactory.setStart(true); // set JSON as the response serializer JacksonJsonProvider provider = new JacksonJsonProvider(); serverFactory.setProvider(provider); } return serverFactory.create(); }
@Bean(name = "entityManagerFactory") @DependsOn("flyway") @Profile("sqlDb") public LocalContainerEntityManagerFactoryBean serverEntityManagerFactory(DataSource dataSource, JpaVendorAdapter vendorAdapter, LoadTimeWeaver loadTimeWeaver, Properties hibernateProperties) { LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); em.setDataSource(dataSource); em.setJpaVendorAdapter(vendorAdapter); em.setLoadTimeWeaver(loadTimeWeaver); em.setJpaProperties(hibernateProperties); em.setPackagesToScan(ENTITIES_PACKAGE); return em; }
@Primary @Bean(name = "customerEntityManager") @DependsOn("transactionManager") public LocalContainerEntityManagerFactoryBean customerEntityManager() throws Throwable { HashMap<String, Object> properties = new HashMap<String, Object>(); properties.put("hibernate.transaction.jta.platform", AtomikosJtaPlatform.class.getName()); properties.put("javax.persistence.transactionType", "JTA"); LocalContainerEntityManagerFactoryBean entityManager = new LocalContainerEntityManagerFactoryBean(); entityManager.setJtaDataSource(customerDataSource()); entityManager.setJpaVendorAdapter(jpaVendorAdapter); entityManager.setPackagesToScan("com.iyihua.sample.domain.customer"); entityManager.setPersistenceUnitName("customerPersistenceUnit"); entityManager.setJpaPropertyMap(properties); return entityManager; }
@Bean @DependsOn("amqpBroker") CachingConnectionFactory connectionFactory() { log.info("Creating connection factory for MQ broker..."); ConnectionFactory cf = new ConnectionFactory(); cf.setHost(hostname); cf.setPort(port); cf.setUsername(userName); cf.setPassword(password); cf.setVirtualHost(virtualHost); cf.setAutomaticRecoveryEnabled(false); if (useSSL) { try { cf.useSslProtocol(); } catch (NoSuchAlgorithmException | KeyManagementException e) { //TODO don't throw raw exceptions throw new RuntimeException(e); } } log.info("Connection factory created."); return new CachingConnectionFactory(cf); }
@Bean @DependsOn(OUTBOUND_ID) public CommandLineRunner kickOff(@Qualifier(OUTBOUND_ID + ".input") MessageChannel in) { return args -> { for (int i = 0; i < 100; i++) { Address address = new Address(Locale.GERMANY.getDisplayCountry(), "Colonge", "50667", "Domkloster", "4"); Recipient recipient = new Recipient("Alexander", "Mustermann", address, address); int amount = ThreadLocalRandom.current().nextInt(1, 15); Order bestellung = new Order(amount, "movieId-" + i, recipient); String bestellungAsJson = ow.writeValueAsString(bestellung); in.send(new GenericMessage<String>(bestellungAsJson)); log.info("ordering movie with movieId-" + i + " " + bestellungAsJson); Thread.sleep(5000); } }; }
@Bean @DependsOn("propertyConfigurer") public ThymeleafTestEngine testEngine() { ThymeleafTestEngine engine = new ThymeleafTestEngine(); engine.setCacheManager(thymeleafCacheManager()); engine.setTemplateModeHandlers(templateModeHandlers()); engine.setAdditionalDialects(additionalDialects()); Set<ITemplateResolver> templateResolvers = new HashSet<ITemplateResolver>(); templateResolvers.add(servletContextTemplateResolver()); templateResolvers.add(fileTemplateResolver()); engine.setTemplateResolvers(templateResolvers); engine.setServletContext(servletContext); engine.setApplicationContext(applicationContext); return engine; }
@Bean(autowire = Autowire.BY_NAME, name = "setupIndexMasterActor") // @Scope("prototype") @DependsOn(value = { "actorSystem" }) public ActorRef setupIndexMasterActor() { final ActorSystem system = applicationContext .getBean(ActorSystem.class); final SetupIndexService setupIndexService = applicationContext .getBean(SetupIndexService.class); final SampleDataGeneratorService sampleDataGeneratorService = applicationContext .getBean(SampleDataGeneratorService.class); final IndexProductDataService indexProductData = applicationContext .getBean(IndexProductDataService.class); return system.actorOf( Props.create(SetupIndexMasterActor.class, setupIndexService, sampleDataGeneratorService, indexProductData) .withDispatcher("setupIndexMasterActorDispatch"), "setupIndexMasterActor"); }
/** * JPA entity manager factory bean. * Depends on the hsqlDbServer bean, in order to create the embedded * database, if one is to be used, before the entity manager factory. */ @Bean @DependsOn("hsqlDbServer") public LocalContainerEntityManagerFactoryBean entityManagerFactory() { /* JPA entity manager factory. */ final LocalContainerEntityManagerFactoryBean theJpaEntityManagerFactory = new LocalContainerEntityManagerFactoryBean(); theJpaEntityManagerFactory.setDataSource(dataSource()); theJpaEntityManagerFactory.setPersistenceUnitName("message-cowboy"); theJpaEntityManagerFactory.setJpaProperties(jpaProperties()); /* JPA vendor adapter. */ final EclipseLinkJpaVendorAdapter theJpaVendorAdapter = new EclipseLinkJpaVendorAdapter(); theJpaVendorAdapter.setShowSql(true); theJpaEntityManagerFactory.setJpaVendorAdapter(theJpaVendorAdapter); return theJpaEntityManagerFactory; }
@Bean @DependsOn({"cacheManager", "springLiquibase"}) public LocalContainerEntityManagerFactoryBean entityManagerFactory() { final HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter(); jpaVendorAdapter.setDatabase(jpaVendorDatabase); final Map<String, Object> jpaProperties = new LinkedHashMap<>(); jpaProperties.put("hibernate.cache.region.factory_class", hibernateEhcacheRegionFactoryClass); jpaProperties.put("hibernate.cache.use_query_cache", hibernateUseQueryCache); jpaProperties.put("hibernate.cache.use_second_level_cache", hibernateUseSecondLevelCache); jpaProperties.put("hibernate.hbm2ddl.auto", hibernateHbm2ddl); final LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); entityManagerFactoryBean.setDataSource(dataSource()); entityManagerFactoryBean.setJpaDialect(new HibernateJpaDialect()); entityManagerFactoryBean.setJpaVendorAdapter(jpaVendorAdapter); entityManagerFactoryBean.setPackagesToScan("org.unidle.domain"); entityManagerFactoryBean.setJpaPropertyMap(jpaProperties); entityManagerFactoryBean.setMappingResources("jpa/orm.xml"); return entityManagerFactoryBean; }
/** * 下面两个配置主要用来开启shiro aop注解支持. 使用代理方式;所以需要开启代码支持; * @return */ @Bean @DependsOn("lifecycleBeanPostProcessor") public DefaultAdvisorAutoProxyCreator getDefaultAdvisorAutoProxyCreator() { DefaultAdvisorAutoProxyCreator daap = new DefaultAdvisorAutoProxyCreator(); daap.setProxyTargetClass(true); return daap; }
@DependsOn("testProducer2") @Bean QueueConsumer<String> testConsumer1() { return new SpringQueueConsumer<String>(queueId1, String.class) { @Nonnull @Override public TaskExecutionResult execute(@Nonnull Task<String> task) { return TaskExecutionResult.finish(); } }; }
@DependsOn("testConsumer1") @Bean QueueConsumer<String> testConsumer2() { return new SpringQueueConsumer<String>(queueId2, String.class) { @Nonnull @Override public TaskExecutionResult execute(@Nonnull Task<String> task) { return TaskExecutionResult.finish(); } }; }
@DependsOn("springThreadLifecycleListener2") @Bean SpringQueueExternalExecutor springQueueExternalExecutor1() { SpringQueueExternalExecutor mock = mock(SpringQueueExternalExecutor.class); doReturn(queueId1).when(mock).getQueueId(); return mock; }
@DependsOn("springQueueExternalExecutor1") @Bean SpringQueueExternalExecutor springQueueExternalExecutor2() { SpringQueueExternalExecutor mock = mock(SpringQueueExternalExecutor.class); doReturn(queueId2).when(mock).getQueueId(); return mock; }
@DependsOn("testProducer2") @Bean QueueConsumer<String> testConsumer1() { return new SpringQueueConsumer<String>(queueId, String.class) { @Nonnull @Override public TaskExecutionResult execute(@Nonnull Task<String> task) { return TaskExecutionResult.finish(); } }; }
@DependsOn("testConsumer1") @Bean QueueConsumer<String> testConsumer2() { return new SpringQueueConsumer<String>(queueId, String.class) { @Nonnull @Override public TaskExecutionResult execute(@Nonnull Task<String> task) { return TaskExecutionResult.finish(); } }; }
@DependsOn("springThreadLifecycleListener2") @Bean SpringQueueExternalExecutor springQueueExternalExecutor1() { SpringQueueExternalExecutor mock = mock(SpringQueueExternalExecutor.class); doReturn(queueId).when(mock).getQueueId(); return mock; }
@DependsOn("springQueueExternalExecutor1") @Bean SpringQueueExternalExecutor springQueueExternalExecutor2() { SpringQueueExternalExecutor mock = mock(SpringQueueExternalExecutor.class); doReturn(queueId).when(mock).getQueueId(); return mock; }
@Bean @DependsOn("newOrderValidator") public Map<EBrokerCommands, IJsonRequestValidator> brokerRequestValidators() { return ImmutableMap.<EBrokerCommands, IJsonRequestValidator>builder() .put(EBrokerCommands.ORDER_NEW, newOrderValidator()) .put(EBrokerCommands.REQUEST_ABORT, new RequestAbortValidator()) .put(EBrokerCommands.ORDER_CANCEL, new OrderCancelValidator()) .put(EBrokerCommands.CANCEL_ALL, new CancelAllValidator()) .build(); }
@Bean @DependsOn("awsCredentials") public AmazonDynamoDB amazonDynamoDBClient(AWSCredentials awsCredentials) { AmazonDynamoDBClient awsClient = new AmazonDynamoDBClient(awsCredentials); if (!ENDPOINT_URL.isEmpty()) { LOGGER.info("END POINT " + ENDPOINT_URL); awsClient.setEndpoint(ENDPOINT_URL); awsClient.setSignerRegionOverride("local"); } return awsClient; }
@Bean @DependsOn("lifecycleBeanPostProcessor") public DefaultAdvisorAutoProxyCreator getAutoProxyCreator(){ DefaultAdvisorAutoProxyCreator creator = new DefaultAdvisorAutoProxyCreator(); creator.setProxyTargetClass(true); return creator; }
/** * @return entity manager factory (kern; alleen lezen) */ @Bean(name = ENTITY_MANAGER_KERN) @DependsOn(TRANSACTION_MANAGER) public LocalContainerEntityManagerFactoryBean kernEntityManagerFactory() { final LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); entityManagerFactoryBean.setDataSource(kernDataSource()); entityManagerFactoryBean.setPersistenceUnitName(PERSISTENCE_UNIT_KERN); entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class); entityManagerFactoryBean.setPackagesToScan(PACKAGE_USERTYPES, PACKAGE_STAMGEGEVEN_ENTITY, PACKAGE_BEHEER_VIEW); entityManagerFactoryBean.setJpaProperties(hibernateProperties()); return entityManagerFactoryBean; }
/** * @return entity manager factory (kern; schrijven) */ @Bean(name = ENTITY_MANAGER_MASTER) @DependsOn(TRANSACTION_MANAGER) public LocalContainerEntityManagerFactoryBean masterEntityManagerFactory() { final LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); entityManagerFactoryBean.setDataSource(masterDataSource()); entityManagerFactoryBean.setPersistenceUnitName(PERSISTENCE_UNIT_MASTER); entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class); entityManagerFactoryBean.setPackagesToScan(PACKAGE_USERTYPES, PACKAGE_STAMGEGEVEN_ENTITY, PACKAGE_BEHEER_VIEW); entityManagerFactoryBean.setJpaProperties(hibernateProperties()); return entityManagerFactoryBean; }
/** * @return entity manager factory (archivering; alleen lezen) */ @Bean(name = ENTITY_MANAGER_ARCHIVERING) @DependsOn(TRANSACTION_MANAGER) public LocalContainerEntityManagerFactoryBean archiveringEntityManagerFactory() { final LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); entityManagerFactoryBean.setDataSource(archiveringDataSource()); entityManagerFactoryBean.setPersistenceUnitName(PERSISTENCE_UNIT_ARCHIVERING); entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class); entityManagerFactoryBean.setPackagesToScan(PACKAGE_USERTYPES, PACKAGE_STAMGEGEVEN_ENTITY, PACKAGE_BEHEER_VIEW); entityManagerFactoryBean.setJpaProperties(hibernateProperties()); return entityManagerFactoryBean; }
/** * @return entity manager factory (protocollering; alleen lezen) */ @Bean(name = ENTITY_MANAGER_PROTOCOLLERING) @DependsOn(TRANSACTION_MANAGER) public LocalContainerEntityManagerFactoryBean protocolleringEntityManagerFactory() { final LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); entityManagerFactoryBean.setDataSource(protocolleringDataSource()); entityManagerFactoryBean.setPersistenceUnitName(PERSISTENCE_UNIT_PROTOCOLLERING); entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class); entityManagerFactoryBean.setPackagesToScan(PACKAGE_STAMGEGEVEN_ENTITY, PACKAGE_BEHEER_VIEW); entityManagerFactoryBean.setJpaProperties(hibernateProperties()); return entityManagerFactoryBean; }
@Bean @DependsOn("embeddedMongoServer") public MongoOperations mongoOperations() throws UnknownHostException { MongoClient mongo = new MongoClient("localhost", this.embeddedMongoPort); return new MongoTemplate(mongo, "test"); }
@Description("AuthenticationManager that will generate an authentication token unlike {PreAuthenticatedAuthenticationProvider}") @Bean @DependsOn({"defaultCalendarService"}) public CalendarUserAuthenticationProvider calendarUserAuthenticationProvider( CalendarService calendarService, PasswordEncoder passwordEncoder){ return new CalendarUserAuthenticationProvider(calendarService, passwordEncoder); }
@Description("AuthenticationMnager that will generate an authentication token unlike {PreAuthenticatedAuthenticationProvider}") @Bean @DependsOn({"defaultCalendarService"}) public CalendarUserAuthenticationProvider calendarUserAuthenticationProvider( CalendarService calendarService, PasswordEncoder passwordEncoder){ return new CalendarUserAuthenticationProvider(calendarService, passwordEncoder); }
/** * This method is creating jobLauncher bean * * @return SimpleJobLauncher */ @Bean @DependsOn("jobRepository") public JobLauncherWithAdditionalRestartCapabilities jobLauncher() { this.jobLauncher = new JobLauncherWithAdditionalRestartCapabilities(); try { this.jobLauncher.setJobRepository(this.jobRepository.getObject()); } catch (Exception e) { throw new BeanCreationException("Could not create BatchJobOperator", e); } return this.jobLauncher; }
/** * This method is creating jobExplorer bean * * @return JobExplorerFactoryBean */ @Bean @DependsOn("dataSource") public JobExplorerFactoryBean jobExplorer() { this.jobExplorer = new JobExplorerFactoryBean(); this.jobExplorer.setDataSource(this.dataSource); return this.jobExplorer; }
/** * This method is creating JobRegistryBeanPostProcessor * * @return JobRegistryBeanPostProcessor */ @Bean @DependsOn("jobRegistry") public JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor() { JobRegistryBeanPostProcessor postProcessor = new JobRegistryBeanPostProcessor(); postProcessor.setJobRegistry(this.jobRegistry); return postProcessor; }