本文整理汇总了Java中org.springframework.context.annotation.Bean类的典型用法代码示例。如果您正苦于以下问题:Java Bean类的具体用法?Java Bean怎么用?Java Bean使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Bean类属于org.springframework.context.annotation包,在下文中一共展示了Bean类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mqProducer
import org.springframework.context.annotation.Bean; //导入依赖的package包/类
@Bean
@ConditionalOnClass(DefaultMQProducer.class)
@ConditionalOnMissingBean(DefaultMQProducer.class)
@ConditionalOnProperty(prefix = "spring.rocketmq", value = {"nameServer", "producer.group"})
public DefaultMQProducer mqProducer(RocketMQProperties rocketMQProperties) {
RocketMQProperties.Producer producerConfig = rocketMQProperties.getProducer();
String groupName = producerConfig.getGroup();
Assert.hasText(groupName, "[spring.rocketmq.producer.group] must not be null");
DefaultMQProducer producer = new DefaultMQProducer(producerConfig.getGroup());
producer.setNamesrvAddr(rocketMQProperties.getNameServer());
producer.setSendMsgTimeout(producerConfig.getSendMsgTimeout());
producer.setRetryTimesWhenSendFailed(producerConfig.getRetryTimesWhenSendFailed());
producer.setRetryTimesWhenSendAsyncFailed(producerConfig.getRetryTimesWhenSendAsyncFailed());
producer.setMaxMessageSize(producerConfig.getMaxMessageSize());
producer.setCompressMsgBodyOverHowmuch(producerConfig.getCompressMsgBodyOverHowmuch());
producer.setRetryAnotherBrokerWhenNotStoreOK(producerConfig.isRetryAnotherBrokerWhenNotStoreOk());
return producer;
}
示例2: taskMessageListenerContainer
import org.springframework.context.annotation.Bean; //导入依赖的package包/类
@Bean
@Autowired
public DefaultMessageListenerContainer taskMessageListenerContainer(JmsExternalTaskListener externalTaskListener
, ConnectionFactory receiverConnectionFactory
, ActiveMQQueue taskQueue) {
DefaultMessageListenerContainer listenerContainer = new DefaultMessageListenerContainer();
listenerContainer.setMessageListener(externalTaskListener);
listenerContainer.setDestination(taskQueue);
listenerContainer.setConnectionFactory(receiverConnectionFactory);
listenerContainer.setAcceptMessagesWhileStopping(false);
listenerContainer.setSessionTransacted(true);
listenerContainer.setConcurrentConsumers(concurrentConsumers);
listenerContainer.setMaxMessagesPerTask(maxMessagesPerTask);
listenerContainer.setReceiveTimeout(receiveTimeout);
return listenerContainer;
}
示例3: bbTaskScheduler
import org.springframework.context.annotation.Bean; //导入依赖的package包/类
@Bean
public TaskScheduler bbTaskScheduler() {
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setThreadNamePrefix("API-Schd-ThrP-");
taskScheduler.setAwaitTerminationSeconds(1);
taskScheduler.setRejectedExecutionHandler(new ThreadPoolTaskRejectedHandler());
return taskScheduler;
}
示例4: keyGenerator
import org.springframework.context.annotation.Bean; //导入依赖的package包/类
/**
* this was used to generate unique key for each method, the key will be like:
* className + methodName + args.
*/
@Bean
public KeyGenerator keyGenerator() {
return new KeyGenerator() {
@Override
public Object generate(Object target, Method method, Object... params) {
StringBuilder sb = new StringBuilder();
sb.append(target.getClass().getName());
sb.append(":");
sb.append(method.getName());
sb.append(":");
for (Object obj : params) {
sb.append(String.valueOf(obj));
sb.append(":");
}
return sb.toString();
}
};
}
示例5: jaasAuthenticationHandlers
import org.springframework.context.annotation.Bean; //导入依赖的package包/类
@ConditionalOnMissingBean(name = "jaasAuthenticationHandlers")
@RefreshScope
@Bean
public List<AuthenticationHandler> jaasAuthenticationHandlers() {
return casProperties.getAuthn().getJaas()
.stream()
.filter(jaas -> StringUtils.isNotBlank(jaas.getRealm()))
.map(jaas -> {
final JaasAuthenticationHandler h =
new JaasAuthenticationHandler(jaas.getName(),
servicesManager, jaasPrincipalFactory(), null);
h.setKerberosKdcSystemProperty(jaas.getKerberosKdcSystemProperty());
h.setKerberosRealmSystemProperty(jaas.getKerberosRealmSystemProperty());
h.setRealm(jaas.getRealm());
h.setPasswordEncoder(Beans.newPasswordEncoder(jaas.getPasswordEncoder()));
if (jaasPasswordPolicyConfiguration != null) {
h.setPasswordPolicyConfiguration(jaasPasswordPolicyConfiguration);
}
h.setPrincipalNameTransformer(Beans.newPrincipalNameTransformer(
jaas.getPrincipalTransformation()));
h.setCredentialSelectionPredicate(Beans.newCredentialSelectionPredicate(
jaas.getCredentialCriteria()));
return h;
})
.collect(Collectors.toList());
}
示例6: persoonsvraagWebserviceVerzoekVerwerker
import org.springframework.context.annotation.Bean; //导入依赖的package包/类
/**
* {@link BevragingVerzoekVerwerker} specifiek voor GBA Ad hoc webservice(Persoons)vraag.
* @return de GBA Ad hoc webservice (Persoons)vraag verwerker
*/
@Bean
@Named("gbaPersoonsvraagWebserviceVerwerker")
public BevragingVerzoekVerwerker<PersoonsvraagWebserviceVerzoek> persoonsvraagWebserviceVerzoekVerwerker() {
return new GeneriekeBevragingVerzoekVerwerker<PersoonsvraagWebserviceVerzoek, BevragingResultaat>() {
};
}
示例7: createDataSource
import org.springframework.context.annotation.Bean; //导入依赖的package包/类
@Bean
public DataSource createDataSource() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(this.url);
config.setUsername(this.username);
config.setPassword(this.password);
config.addDataSourceProperty("poolName", this.poolName);
config.addDataSourceProperty("connectionTimeout", this.connectionTimeout);
config.addDataSourceProperty("autoCommit", "false");
return new HikariDataSource(config);
}
示例8: resourceDetails
import org.springframework.context.annotation.Bean; //导入依赖的package包/类
@Bean
public OAuth2ProtectedResourceDetails resourceDetails() {
AuthorizationCodeResourceDetails details = new AuthorizationCodeResourceDetails();
details.setClientId(properties.getClientId());
details.setClientSecret(properties.getClientSecret());
// URLs retrieved from https://accounts.google.com/.well-known/openid-configuration
details.setUserAuthorizationUri("https://accounts.google.com/o/oauth2/v2/auth");
details.setAccessTokenUri("https://www.googleapis.com/oauth2/v4/token");
details.setPreEstablishedRedirectUri("http://localhost:8080/google/callback");
details.setScope(Arrays.asList("openid", "email", "profile"));
details.setUseCurrentUri(false);
return details;
}
示例9: corsFilter
import org.springframework.context.annotation.Bean; //导入依赖的package包/类
@Bean
public FilterRegistrationBean corsFilter() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(new CorsFilter());
// Highest priority to authorise OPTION requests.
filterRegistrationBean.setOrder(0);
return filterRegistrationBean;
}
示例10: contextSource
import org.springframework.context.annotation.Bean; //导入依赖的package包/类
/**
* LDAP Server Context
* @return
*/
@Bean
public DefaultSpringSecurityContextSource contextSource() {
return new DefaultSpringSecurityContextSource(
Arrays.asList("ldap://corp.jbcpcalendar.com/"), "dc=corp,dc=jbcpcalendar,dc=com"){{
setUserDn("CN=Administrator,CN=Users,DC=corp,DC=jbcpcalendar,DC=com");
setPassword("admin123!");
}};
}
示例11: rssInputRoute
import org.springframework.context.annotation.Bean; //导入依赖的package包/类
/**
* Camel routes for reading RSS feeds. Routes could be also defined in XML, Groovy or scripting knowledge bases.
*
* @return route builder.
*/
@Bean
public RouteBuilder rssInputRoute() {
return new RouteBuilder() {
// @formatter:off
@SuppressWarnings("unchecked")
@Override
public void configure() throws Exception {
EngineOperations operations = camelRssEngine().getOperations();
Map<String, String> rssSources = operations.getVariable(Map.class, CamelRssConstants.VAR_RSS_SOURCES);
// Read RSS feeds from all configured sources.
rssSources.forEach((source, url) ->
from("rss:" + url + operations.getVariable(CamelRssConstants.VAR_RSS_ENDPOINT_PARAMETERS, "")).routeId(source)
.setHeader(HEADER_SOURCE).constant(source)
.to("direct:rss"));
// Gathers RSS from different sources and sends to Sponge engine as a normalized event.
from("direct:rss").routeId("rss")
.marshal().rss()
// Deduplicate by title.
.idempotentConsumer(xpath("/rss/channel/item/title/text()"),
MemoryIdempotentRepository.memoryIdempotentRepository())
// Conversion from RSS XML to Sponge event with attributes.
.process((exchange) -> exchange.getIn().setBody(operations.event("news")
.set("source", exchange.getIn().getHeader(HEADER_SOURCE))
.set("channel", CamelUtils.xpath(exchange, "/rss/channel/title/text()"))
.set("title", CamelUtils.xpath(exchange, "/rss/channel/item/title/text()"))
.set("link", CamelUtils.xpath(exchange, "/rss/channel/item/link/text()"))
.set("description", CamelUtils.xpath(exchange, "/rss/channel/item/description/text()"))
.make()))
//.filter((exchange) -> false)
.to("sponge:camelRssEngine");
}
// @formatter:on
};
}
示例12: getJobExplorer
import org.springframework.context.annotation.Bean; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(JobExplorer.class)
public JobExplorer getJobExplorer() throws Exception {
BatchConfigurer batchConfigurer = getBatchConfigurer();
if (batchConfigurer != null) {
return batchConfigurer.getJobExplorer();
}
JobExplorerFactoryBean jobExplorerFactoryBean = new JobExplorerFactoryBean();
jobExplorerFactoryBean.setDataSource(dataSource);
return jobExplorerFactoryBean.getObject();
}
示例13: clientValidator
import org.springframework.context.annotation.Bean; //导入依赖的package包/类
@Bean
public ClientValidator clientValidator() throws Exception {
final ClientValidator mock = mock(ClientValidator.class);
when(mock.isValid(eq(GrantTypes.OPENID), anyString())).thenReturn(true);
return mock;
}
示例14: subscriptionAdminClient
import org.springframework.context.annotation.Bean; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public SubscriptionAdminClient subscriptionAdminClient() {
try {
return SubscriptionAdminClient.create(
SubscriptionAdminSettings.newBuilder()
.setCredentialsProvider(this.finalCredentialsProvider)
.build());
}
catch (IOException ioe) {
throw new PubSubException("An error occurred while creating SubscriptionAdminClient.",
ioe);
}
}
示例15: createRestApi
import org.springframework.context.annotation.Bean; //导入依赖的package包/类
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.wind.web"))
.paths(PathSelectors.any())
.build();
}