下面列出了怎么用org.springframework.context.annotation.Profile的API类实例代码及写法,或者点击链接到github查看源代码。
@Profile("trace")
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("Let's inspect the beans provided by Spring Boot:\n");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
System.out.println("---");
};
}
@Profile("trace")
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("Let's inspect the beans provided by Spring Boot:\n");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
System.out.println("---");
};
}
@Profile({ Modules.REPLICATION })
@Bean
Supplier<CloseableMetaStoreClient> replicaMetaStoreClientSupplier(
ReplicaCatalog replicaCatalog,
@Value("#{replicaHiveConf}") HiveConf replicaHiveConf,
ConditionalMetaStoreClientFactoryManager conditionalMetaStoreClientFactoryManager) {
String metaStoreUris = replicaCatalog.getHiveMetastoreUris();
if (metaStoreUris == null) {
// Default to Thrift is not specified - optional attribute in ReplicaCatalog
metaStoreUris = ThriftHiveMetaStoreClientFactory.ACCEPT_PREFIX;
}
MetaStoreClientFactory replicaMetaStoreClientFactory = conditionalMetaStoreClientFactoryManager
.factoryForUri(metaStoreUris);
return metaStoreClientSupplier(replicaHiveConf, replicaCatalog.getName(), replicaCatalog.getMetastoreTunnel(),
replicaMetaStoreClientFactory);
}
@Profile({ Modules.REPLICATION })
@Bean
Supplier<CloseableMetaStoreClient> sourceMetaStoreClientSupplier(
SourceCatalog sourceCatalog,
@Value("#{sourceHiveConf}") HiveConf sourceHiveConf,
ConditionalMetaStoreClientFactoryManager conditionalMetaStoreClientFactoryManager) {
String metaStoreUris = sourceCatalog.getHiveMetastoreUris();
if (metaStoreUris == null) {
// Default to Thrift is not specified - optional attribute in SourceCatalog
metaStoreUris = ThriftHiveMetaStoreClientFactory.ACCEPT_PREFIX;
}
MetaStoreClientFactory sourceMetaStoreClientFactory = conditionalMetaStoreClientFactoryManager
.factoryForUri(metaStoreUris);
return metaStoreClientSupplier(sourceHiveConf, sourceCatalog.getName(), sourceCatalog.getMetastoreTunnel(),
sourceMetaStoreClientFactory);
}
@Profile("trace")
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("Let's inspect the beans provided by Spring Boot:\n");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
System.out.println("---");
};
}
@Profile("trace")
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("Let's inspect the beans provided by Spring Boot:\n");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
System.out.println("---");
};
}
@Profile("trace")
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("Let's inspect the beans provided by Spring Boot:\n");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
System.out.println("---");
};
}
@Profile("trace")
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("Let's inspect the beans provided by Spring Boot:\n");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
System.out.println("---");
};
}
@Bean
@Profile("local")
public Platform localDeployers(LocalPlatformProperties localPlatformProperties) {
List<Deployer> deployers = new ArrayList<>();
Map<String, LocalDeployerProperties> localDeployerPropertiesMap = localPlatformProperties.getAccounts();
if (localDeployerPropertiesMap.isEmpty()) {
localDeployerPropertiesMap.put("default", new LocalDeployerProperties());
}
for (Map.Entry<String, LocalDeployerProperties> entry : localDeployerPropertiesMap
.entrySet()) {
LocalAppDeployer localAppDeployer = new LocalAppDeployer(entry.getValue());
Deployer deployer = new Deployer(entry.getKey(), "local", localAppDeployer);
deployer.setDescription(prettyPrintLocalDeployerProperties(entry.getValue()));
deployers.add(deployer);
}
return new Platform("Local", deployers);
}
@Bean
@Profile("legacy")
public DataSource legacyDataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
dataSource.setUrl(SettingsService.getDefaultJDBCUrl());
dataSource.setUsername(SettingsService.getDefaultJDBCUsername());
dataSource.setPassword(SettingsService.getDefaultJDBCPassword());
return dataSource;
}
@Profile("default")
@Bean
public HttpServer nettyHttpServer(ApplicationContext context) {
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create().host("localhost").port(this.port);
return httpServer.handle(adapter);
}
@Bean
@Profile("locator-configurer")
LocatorConfigurer clusterLocatorConfigurer(
@Value("${spring.data.gemfire.locators:localhost[10334]}") String locators) {
return (beanName, bean) -> bean.getGemFireProperties()
.setProperty(GemFireProperties.LOCATORS.toString(), locators);
}
@Profile("default")
@Bean
public HttpServer nettyHttpServer(ApplicationContext context) {
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create().host("localhost").port(this.port);
return httpServer.handle(adapter);
}
@Profile("test")
@Bean("testDataSource")
public DataSource dataSourceTest(@Value("${db.password}") String pwd) throws PropertyVetoException {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setUser(user);
dataSource.setPassword(pwd);
dataSource.setDriverClass(driverClass);
dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/test");
return dataSource;
}
@Profile("dev")
@Bean("devDataSource")
public DataSource dataSourceDev(@Value("${db.password}") String pwd) throws PropertyVetoException {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setUser(user);
dataSource.setPassword(pwd);
dataSource.setDriverClass(driverClass);
dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/dev");
return dataSource;
}
@Profile("prod")
@Bean("prodDataSource")
public DataSource dataSourceProd(@Value("${db.password}") String pwd) throws PropertyVetoException {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setUser(user);
dataSource.setPassword(pwd);
dataSource.setDriverClass(driverClass);
dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/prod");
return dataSource;
}
@Profile("default")
@Bean
public HttpServer nettyHttpServer(ApplicationContext context) {
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create().host("localhost").port(this.port);
return httpServer.handle(adapter);
}
@Profile("default")
@Bean
public HttpServer nettyHttpServer(ApplicationContext context) {
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create().host("localhost").port(this.port);
return httpServer.handle(adapter);
}
/**
* Open the TCP port for the H2 database, so it is available remotely.
*
* @return the H2 database TCP server.
* @throws SQLException if the server failed to start.
*/
@Bean(initMethod = "start", destroyMethod = "stop")
@Profile(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)
public Object h2TCPServer() throws SQLException {
String port = getValidPortForH2();
log.debug("H2 database is available on port {}", port);
return H2ConfigurationHelper.createServer(port);
}
@Profile("default")
@Bean
public HttpServer nettyHttpServer(ApplicationContext context) {
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create().host("localhost").port(this.port);
return httpServer.handle(adapter);
}
@Profile("default")
@Bean
public HttpServer nettyHttpServer(ApplicationContext context) {
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create().host("localhost").port(this.port);
return httpServer.handle(adapter);
}
@Profile("local")
@Bean
CommandLineRunner init(Catalogue catalogue) {
return args -> {
catalogue.addBook("Joshua Bloch", "Effective Java", "0321125215").get();
catalogue.addBookInstance("0321125215", BookType.Restricted).get();
};
}
@Bean
@Profile("!test")
public CommandLineRunner batchMessageConsumerRunner() {
return args -> {
//Just comment out the examples to run
//simpleKafkaMessagingExample.execute();
//multiPartitionMessagingExample.execute();
//batchMessageConsumingExample.execute();
//kafkaStreamExample.execute();
};
}
@Profile("default")
@Bean
public HttpServer nettyHttpServer(ApplicationContext context) {
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create().host("localhost").port(this.port);
return httpServer.handle(adapter);
}
@Profile("javaconfig")
@Bean
@Transformer(inputChannel="textInChannel",
outputChannel="fileWriterChannel")
public GenericTransformer<String, String> upperCaseTransformer() {
return text -> text.toUpperCase();
}
@Profile("default")
@Bean
public HttpServer nettyHttpServer(ApplicationContext context) {
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create().host("localhost").port(this.port);
return httpServer.handle(adapter);
}
@Profile("default")
@Bean
public HttpServer nettyHttpServer(ApplicationContext context) {
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create().host("localhost").port(this.port);
return httpServer.handle(adapter);
}
/**
* Open the TCP port for the H2 database, so it is available remotely.
*
* @return the H2 database TCP server
* @throws SQLException if the server failed to start
*/
@Bean(initMethod = "start", destroyMethod = "stop")
@Profile(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT)
public Object h2TCPServer() throws SQLException {
log.debug("Starting H2 database");
return H2ConfigurationHelper.createServer();
}
@Profile({ Modules.REPLICATION })
@Bean
PartitionTransformation partitionTransformation(List<PartitionTransformation> transformations) {
if (transformations == null) {
transformations = Collections.emptyList();
}
return new CompositePartitionTransformation(transformations);
}
@Bean(name = "authenticationProvider")
@Profile("auto-mode-preauth")
public PreAuthenticatedAuthenticationProvider externalAuthenticationProvider()
{
PreAuthenticatedAuthenticationProvider authProvider =
new PreAuthenticatedAuthenticationProvider();
authProvider.setPreAuthenticatedUserDetailsService(
new UserDetailsByNameServiceWrapper<PreAuthenticatedAuthenticationToken>(
userDetailsService()));
return authProvider;
}