Java Code Examples for org.springframework.context.annotation.Scope

The following are top voted examples for showing how to use org.springframework.context.annotation.Scope. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: spring-security-oauth2-boot   File: OAuth2RestOperationsConfiguration.java   View source code 9 votes vote down vote up
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public DefaultOAuth2ClientContext oauth2ClientContext() {
	DefaultOAuth2ClientContext context = new DefaultOAuth2ClientContext(
			new DefaultAccessTokenRequest());
	Authentication principal = SecurityContextHolder.getContext()
			.getAuthentication();
	if (principal instanceof OAuth2Authentication) {
		OAuth2Authentication authentication = (OAuth2Authentication) principal;
		Object details = authentication.getDetails();
		if (details instanceof OAuth2AuthenticationDetails) {
			OAuth2AuthenticationDetails oauthsDetails = (OAuth2AuthenticationDetails) details;
			String token = oauthsDetails.getTokenValue();
			context.setAccessToken(new DefaultOAuth2AccessToken(token));
		}
	}
	return context;
}
 
Example 2
Project: spring-microservice-sample   File: DataJpaConfig.java   View source code 6 votes vote down vote up
@Bean
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public AuditorAware<Username> auditorAware() {

    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

    log.debug("current authentication:" + authentication);

    if (authentication == null || !authentication.isAuthenticated()) {
        return () -> Optional.<Username>empty();
    }

    return () -> Optional.of(
        Username.builder()
            .username(((UserDetails) authentication.getPrincipal()).getUsername())
            .build()
    );

}
 
Example 3
Project: OAuth-2.0-Cookbook   File: FacebookConfiguration.java   View source code 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean(Facebook.class)
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public Facebook facebook(ConnectionRepository repository) {
	Connection<Facebook> connection = repository
			.findPrimaryConnection(Facebook.class);
	return connection != null ? connection.getApi() : null;
}
 
Example 4
Project: jaffa-framework   File: JaffaRulesConfig.java   View source code 6 votes vote down vote up
/**
 * Configures the AOP file System watcher to observe the paths passed in for the
 * jboss aop folder.
 */
@Bean
@Scope(BeanDefinition.SCOPE_SINGLETON)
@Autowired
public AopXmlLoader aopFolderWatcher(Environment env) throws JaffaRulesFrameworkException {

    // Check to see if this is supported. If explicitly disabled, then return early.
    if (env.containsProperty("jaffa.aop.springconfig.disabled") &&
            env.getProperty("jaffa.aop.springconfig.disabled").equals("true")) {
        return null;
    }

    String aopPath =
            env.containsProperty("jboss.aop.path") ?
                    env.getProperty("jboss.aop.path") :
                    AopConstants.DEFAULT_AOP_PATTERN;

    List<String> paths = Arrays.asList(aopPath.split(";"));
    return new AopXmlLoader(paths);
}
 
Example 5
Project: eventapis   File: StoreApi.java   View source code 6 votes vote down vote up
@Bean
@Scope("singleton")
@Qualifier("operationIgniteClient")
@ConditionalOnMissingBean(KafkaOperationRepository.class)
public Ignite createIgnite(ApplicationContext applicationContext) throws IgniteCheckedException {
    IgniteConfiguration cfg = new IgniteConfiguration();
    cfg.setClientMode(true);
    cfg.setPeerClassLoadingEnabled(false);
    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
    TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
    ipFinder.setAddresses(Arrays.asList(clientAddress.split(",")));
    discoSpi.setIpFinder(ipFinder);
    cfg.setDiscoverySpi(discoSpi);
    cfg.setMetricsLogFrequency(0);
    return IgniteSpring.start(cfg,applicationContext);
}
 
Example 6
Project: bean-grid   File: BeanGridConfiguration.java   View source code 6 votes vote down vote up
@Bean
@Scope(scopeName = "prototype")
@SuppressWarnings("unchecked")
public <ITEM> Grid<ITEM> configureBeanGrid(DependencyDescriptor dependencyDescriptor) {
	logger.debug("Configuring Vaadin Grid as bean");

	long timestamp = System.currentTimeMillis();

	ResolvableType injectionPointType = dependencyDescriptor.getResolvableType();
	if (!injectionPointType.hasGenerics()) {
		throw new IllegalStateException("Grid injection point is expected to declare a static item type");
	}

	ResolvableType genericType = injectionPointType.getGeneric();
	Class<ITEM> itemType = (Class<ITEM>) genericType.resolve();

	logger.debug("Vaadin Grid will use " + itemType.getCanonicalName() + " as item type");

	Grid<ITEM> grid = configureGridInstance(itemType);
	long configTime = System.currentTimeMillis() - timestamp;
	logger.debug("Done configuring Grid for " + itemType.getName() + " in " + configTime + "ms");

	return grid;
}
 
Example 7
Project: cassandra-client   File: CassandraClientUIConfiguration.java   View source code 6 votes vote down vote up
@Bean
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public Menu fileMenu() {
    Menu file = new Menu(localeService.getMessage("ui.menu.file"));
    file.setMnemonicParsing(false);

    MenuItem connect = new MenuItem(localeService.getMessage("ui.menu.file.connect"));
    connect.setMnemonicParsing(false);
    connect.setOnAction(event -> newConnectionBox(getMainView().getPrimaryStage(),
            (data) -> getMainController().loadTables(data)));

    MenuItem manager = new MenuItem(localeService.getMessage("ui.menu.file.manager"));
    manager.setMnemonicParsing(false);
    manager.setOnAction(event -> connectionManager());
    file.getItems().addAll(connect, manager);
    return file;
}
 
Example 8
Project: jaffa-framework   File: JaffaRulesConfig.java   View source code 5 votes vote down vote up
/**
 * Configure the MaxValue Validator
 *
 * @return MaxValue Validator
 */
@Bean(name = "max-value")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public MaxValueValidator maxValueValidator() {
    MaxValueValidator validator = new MaxValueValidator();
    validator.setRuleEvaluator(ruleHelper());
    return validator;
}
 
Example 9
Project: proxylive   File: StreamProcessorFactory.java   View source code 5 votes vote down vote up
@Bean
@Scope(value = "prototype")
public IStreamProcessor StreamProcessor(int mode, String clientIdentifier, String channel, String profile) {
    String identifier = new Date().getTime() + clientIdentifier;
    String identifier64 = new String(Base64.getEncoder().encode(identifier.getBytes()));

    HttpSoureStreamProcessor sourceStreamProcessor = (HttpSoureStreamProcessor) context.getBean("HttpSoureStreamProcessor", identifier64, channel);

    IStreamProcessor streamProcessor = null;
    if (profile==null) {
        streamProcessor = sourceStreamProcessor;
    } else {
        //streamProcessor = (IStreamProcessor) context.getBean("TranscodedStreamProcessor", identifier64, sourceStreamProcessor, profile);
        streamProcessor = (IStreamProcessor) context.getBean("DirectTranscodedStreamProcessor", identifier64, channel, profile);
    }
    IStreamProcessor postStreamProcessor = null;
    switch (mode) {
        case ProxyLiveConstants.HLS_MODE:
            postStreamProcessor = (IStreamProcessor) context.getBean("HLSStreamProcessor", identifier64, streamProcessor);
            break;
        case ProxyLiveConstants.STREAM_MODE:
            postStreamProcessor = streamProcessor;
            break;
    }
    return postStreamProcessor;

}
 
Example 10
Project: jaffa-framework   File: JaffaRulesConfig.java   View source code 5 votes vote down vote up
/**
 * Configure the MinLength Validator
 *
 * @return MinLength Validator
 */
@Bean(name = "min-length")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public MinLengthValidator minLengthValidator() {
    MinLengthValidator validator = new MinLengthValidator();
    validator.setRuleEvaluator(ruleHelper());
    return validator;
}
 
Example 11
Project: Spring-5.0-Cookbook   File: BeanConfig.java   View source code 5 votes vote down vote up
@Bean(name="empRec2")
@Scope("prototype")
public Employee getEmpRecord2(){
	Employee empRec2 = new Employee();
	empRec2.setFirstName("Juan");
	empRec2.setLastName("Luna");
	empRec2.setAge(50);
	empRec2.setBirthdate(new Date(45,9,30));
	empRec2.setPosition("historian");
	empRec2.setSalary(100000.00);
	empRec2.setDept(getDept2());
	return empRec2;
}
 
Example 12
Project: jaffa-framework   File: JaffaRulesConfig.java   View source code 5 votes vote down vote up
/**
 * Configure the GenericForeignKey Validator
 *
 * @return GenericForeignKey Validator
 */
@Bean(name = "generic-foreign-key")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public GenericForeignKeyValidator genericForeignKeyValidator() {
    GenericForeignKeyValidator validator = new GenericForeignKeyValidator();
    validator.setRuleEvaluator(ruleHelper());
    return validator;
}
 
Example 13
Project: redirector   File: IntegrationTestBeans.java   View source code 5 votes vote down vote up
@Bean
@Scope(AppScope.APP_SCOPE)
IAppModelFacade modelFacade(String appName, IDataSourceConnector connector, IDataChangePoller dataChangePoller,
                            IWebServiceClient dataFacadeWebServiceClient, ZKConfig config) {
    return new AppModelRestFacade.Builder()
            .withConnector(connector)
            .forApplication(appName)
            .withDataChangePoller(dataChangePoller)
            .withWebServiceClient(dataFacadeWebServiceClient)
            .withZkConfig(config)
            .build();
}
 
Example 14
Project: xm-commons   File: LepSpringConfiguration.java   View source code 5 votes vote down vote up
@Bean
@Scope(SCOPE_SINGLETON)
protected LepManager lepManager() {
    return new SpringLepManager(extensionService(),
                                lepExecutor(),
                                applicationLepProcessingEventPublisher(),
                                lepResourceService());
}
 
Example 15
Project: talchain   File: FramingTest.java   View source code 5 votes vote down vote up
@Bean
@Scope("prototype")
public MessageCodec messageCodec() {
    MessageCodec codec = new MessageCodec();
    codec.setMaxFramePayloadSize(16);
    System.out.println("SysPropConfig1.messageCodec");
    return codec;
}
 
Example 16
Project: talchain   File: FramingTest.java   View source code 5 votes vote down vote up
@Bean
@Scope("prototype")
public MessageCodec messageCodec() {
    MessageCodec codec = new MessageCodec();
    codec.setMaxFramePayloadSize(16);
    System.out.println("SysPropConfig2.messageCodec");
    return codec;
}
 
Example 17
Project: OAuth-2.0-Cookbook   File: GoogleConfigurerAdapter.java   View source code 5 votes vote down vote up
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public Google google(final ConnectionRepository repository) {
	final Connection<Google> connection = repository
			.findPrimaryConnection(Google.class);
	return connection != null ? connection.getApi() : null;
}
 
Example 18
Project: OAuth-2.0-Cookbook   File: GitHubConfiguration.java   View source code 5 votes vote down vote up
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public GitHub gitHub(ConnectionRepository repository) {
	Connection<GitHub> connection = repository
			.findPrimaryConnection(GitHub.class);
	return connection != null ? connection.getApi() : null;
}
 
Example 19
Project: syndesis   File: Application.java   View source code 5 votes vote down vote up
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
@Bean(name = "verifier-context", initMethod = "start", destroyMethod = "stop")
public static CamelContext verifierContext() {
    CamelContext context = new DefaultCamelContext();
    context.setNameStrategy(new ExplicitCamelContextNameStrategy("verifier-context"));
    context.disableJMX();

    return context;
}
 
Example 20
Project: syndesis   File: TwitterVerifierAutoConfiguration.java   View source code 5 votes vote down vote up
@Bean("twitter")
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
@Lazy
@ConditionalOnProperty(prefix = "io.syndesis.connector.twitter.verifier", name = "enabled", matchIfMissing = true)
public Verifier twitterVerifier() {
    return new TwitterVerifier();
}
 
Example 21
Project: jaffa-framework   File: PropertyPlaceholderConfig.java   View source code 5 votes vote down vote up
/**
 * Load the properties files used in application contexts here
 *
 * @return the initialized instance of the PropertyPlaceholderConfigurer class
 */
@Bean(name="properties")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public PropertyPlaceholderConfigurer conversionService() {
    PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
    Resource resource1 = new ClassPathResource("application_file_1.properties");
    Resource resource2 = new ClassPathResource("application_file_2.properties");
    configurer.setLocations(resource1, resource2);
    return configurer;
}
 
Example 22
Project: happylifeplat-tcc   File: MyConfiguration.java   View source code 5 votes vote down vote up
@Bean
@Scope("prototype")
public Feign.Builder feignBuilder() {
    return Feign.builder()
            .requestInterceptor(new TccRestTemplateInterceptor())
            .invocationHandlerFactory(invocationHandlerFactory());
}
 
Example 23
Project: azure-spring-boot   File: AADAuthenticationFilterAutoConfiguration.java   View source code 5 votes vote down vote up
/**
 * Declare AADAuthenticationFilter bean.
 *
 * @return AADAuthenticationFilter bean
 */
@Bean
@Scope("singleton")
@ConditionalOnMissingBean(AADAuthenticationFilter.class)
public AADAuthenticationFilter azureADJwtTokenFilter() {
    LOG.info("AzureADJwtTokenFilter Constructor.");
    return new AADAuthenticationFilter(aadAuthFilterProperties);
}
 
Example 24
Project: jaffa-framework   File: JaffaRulesConfig.java   View source code 5 votes vote down vote up
/**
 * Configure the CaseType Validator
 *
 * @return CaseType Validator
 */
@Bean(name = "case-type")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public CaseTypeValidator caseTypeValidator() {
    CaseTypeValidator validator = new CaseTypeValidator();
    validator.setRuleEvaluator(ruleHelper());
    return validator;
}
 
Example 25
Project: jaffa-framework   File: JaffaRulesConfig.java   View source code 5 votes vote down vote up
/**
 * Configure the Pattern Validator
 *
 * @return Pattern Validator
 */
@Bean(name = "pattern")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public PatternValidator patternValidator() {
    PatternValidator validator = new PatternValidator();
    validator.setRuleEvaluator(ruleHelper());
    return validator;
}
 
Example 26
Project: training-sample   File: AppConfig.java   View source code 5 votes vote down vote up
@Scope("prototype")
@Bean(name = "prototypeBean")
public ExampleScopeBean prototypeBean() {
	ExampleScopeBean exampleScopeBean = new ExampleScopeBean();
	exampleScopeBean.setMessage("hello");
	return exampleScopeBean;
}
 
Example 27
Project: eventapis   File: EventApisFactory.java   View source code 5 votes vote down vote up
@Bean
@Scope("prototype")
public RequestInterceptor opIdInterceptor(@Autowired OperationContext operationContext) {
    return template -> {
        String key = operationContext.getContext();
        if (key != null)
            template.header("opId", key.toString());
    };
}
 
Example 28
Project: eventapis   File: FeignHelper.java   View source code 5 votes vote down vote up
@Bean
@Scope("prototype")
public RequestInterceptor opIdInterceptor() {
    return (template) -> {
        String key = this.operationContext.getContext();
        if (key != null) {
            template.header("opId", key);
        }

    };
}
 
Example 29
Project: travel-agency   File: NexmoConfig.java   View source code 5 votes vote down vote up
@Bean
@Scope("singleton")
public NexmoClient nexmoClientBean() throws InvalidKeySpecException, NoSuchAlgorithmException, InvalidKeyException, IOException {
    AuthMethod tokenAuthMethod = new TokenAuthMethod(this.apiKey, this.apiSecret);
    AuthMethod jwtAuthMethod = new JWTAuthMethod(this.applicationId, new File(this.pathPrivateKey).toPath());
    return new NexmoClient(tokenAuthMethod, jwtAuthMethod);
}
 
Example 30
Project: jwala   File: JvmControlServiceImplTest.java   View source code 5 votes vote down vote up
@Bean
@Scope("prototype")
public JvmControlService getJvmControlService() {
    reset(mockJvmCommandFactory, mockSshConfig, mockShellCommandFactory, mockHistoryFacadeService,
            mockJvmStateService, mockRemoteCommandExecutorService, mockSshConfig,
            mockJvmPersistenceService);

    return new JvmControlServiceImpl(
            mockJvmPersistenceService,
            mockJvmStateService,
            mockHistoryFacadeService);
}
 
Example 31
Project: jaffa-framework   File: JaffaRulesConfig.java   View source code 5 votes vote down vote up
/**
 * Configure the validator factory
 *
 * @return validator factory
 */
@Bean(name = "ruleValidatorFactory")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public RuleValidatorFactory ruleValidatorFactory() {
    RuleValidatorFactory factory = new RuleValidatorFactory();
    factory.addValidatorTypes("mandatory", "max-length", "min-length", "case-type", "max-value", "min-value",
            "candidate-key", "comment", "foreign-key", "generic-foreign-key", "in-list",
            "not-in-list", "partial-foreign-key", "pattern", "primary-key");
    return factory;
}
 
Example 32
Project: jwala   File: BinaryDistributionServiceImplTest.java   View source code 5 votes vote down vote up
@Bean
@Scope("prototype")
public BinaryDistributionService getBinaryDistributionService() {
    reset(mockBinaryDistributionControlService, mockBinaryDistributionLockManager,
            historyFacadeService, mockSshConfig, mockSshConfiguration, mockRemoteCommandExecutorService);
    return new BinaryDistributionServiceImpl();
}
 
Example 33
Project: kalinka   File: ContextConfiguration.java   View source code 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@Bean
public IMessagePublisher messagePublisher(final String className) {

	return createObject(className, IMessagePublisher.class);
}
 
Example 34
Project: cassandra-client   File: CassandraConfiguration.java   View source code 5 votes vote down vote up
@Bean
@Lazy
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public CassandraMappingContext cassandraMapping(Cluster cluster, String keyspace) throws ClassNotFoundException {
    BasicCassandraMappingContext mappingContext = new BasicCassandraMappingContext();
    mappingContext.setBeanClassLoader(classLoader);
    mappingContext.setInitialEntitySet(CassandraEntityClassScanner.scan(getEntityBasePackages()));
    CustomConversions customConversions = customConversions();
    mappingContext.setCustomConversions(customConversions);
    mappingContext.setSimpleTypeHolder(customConversions.getSimpleTypeHolder());
    mappingContext.setUserTypeResolver(new SimpleUserTypeResolver(cluster, keyspace));
    return mappingContext;
}
 
Example 35
Project: jaffa-framework   File: JaffaRulesConfig.java   View source code 5 votes vote down vote up
/**
 * Configure the MinValue Validator
 *
 * @return MinValue Validator
 */
@Bean(name = "min-value")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public MinValueValidator minValueValidator() {
    MinValueValidator validator = new MinValueValidator();
    validator.setRuleEvaluator(ruleHelper());
    return validator;
}
 
Example 36
Project: cassandra-client   File: CassandraClientUIConfiguration.java   View source code 5 votes vote down vote up
@Bean
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public Menu helpMenu() {
    Menu file = new Menu(localeService.getMessage("ui.menu.help"));
    file.setMnemonicParsing(false);

    MenuItem about = new MenuItem(localeService.getMessage("ui.menu.help.about"));
    about.setMnemonicParsing(false);
    about.setOnAction(event -> aboutBox());

    file.getItems().add(about);
    return file;
}
 
Example 37
Project: mongodb-rdbms-sync   File: MvcConfiguration.java   View source code 5 votes vote down vote up
@Bean
@Scope(value = "prototype")
public JobDetailFactoryBean getMonitorJob(){
	JobDetailFactoryBean bean = new JobDetailFactoryBean();
	bean.setJobClass(NodeMonitorJob.class);
	return bean;
}
 
Example 38
Project: mongodb-rdbms-sync   File: MvcConfiguration.java   View source code 5 votes vote down vote up
@Bean
@Scope(value = "prototype")
public JobDetailFactoryBean getEventJob(){
	JobDetailFactoryBean bean = new JobDetailFactoryBean();
	bean.setJobClass(EventJob.class);
	return bean;
}
 
Example 39
Project: Lyrebird   File: FrontendComponents.java   View source code 5 votes vote down vote up
/**
 * Containerize {@link FxmlLoader} so we can add our resource bundle.

 */
@Bean
@Scope(scopeName = SCOPE_PROTOTYPE)
public FxmlLoader fxmlLoader(final ApplicationContext context, final ResourceBundle resourceBundle) {
    final FxmlLoader loader = new FxmlLoader();
    loader.setControllerFactory(context::getBean);
    loader.setResources(resourceBundle);
    return loader;
}
 
Example 40
Project: happylifeplat-transaction   File: RestTemplateConfiguration.java   View source code 4 votes vote down vote up
@Bean
@Scope("prototype")
public Feign.Builder feignBuilder() {
    return Feign.builder().requestInterceptor(new RestTemplateInterceptor());
}