Java Code Examples for org.springframework.core.env.Environment

The following are top voted examples for showing how to use org.springframework.core.env.Environment. 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: gamesboard   File: SocialContext.java   View source code 6 votes vote down vote up
/**
   * Configures the connection factories for Facebook and Twitter.
   * @param cfConfig
   * @param env
   */
  @Override
  public void addConnectionFactories(ConnectionFactoryConfigurer cfConfig, Environment env) {
      cfConfig.addConnectionFactory(new TwitterConnectionFactory(
              env.getProperty("twitter.consumer.key"),
              env.getProperty("twitter.consumer.secret")
      ));
      cfConfig.addConnectionFactory(new GoogleConnectionFactory(
              env.getProperty("twitter.consumer.key"), //TODO !!!!!!!!!!
              env.getProperty("twitter.consumer.secret") //TODO !!!!!!!!!!
      ));
      FacebookConnectionFactory facebookFactory = new FacebookConnectionFactory(
              env.getProperty("facebook.app.id"),
              env.getProperty("facebook.app.secret"));
      facebookFactory.setScope("public_profile,email,user_friends");
cfConfig.addConnectionFactory(facebookFactory);
  }
 
Example 2
Project: juiser   File: JuiserSpringSecurityCondition.java   View source code 6 votes vote down vote up
private boolean isSpringSecurityEnabled(ConditionContext ctx) {

        boolean enabled = true;

        Environment env = ctx.getEnvironment();

        for (String propName : props) {
            if (env.containsProperty(propName)) {
                if (!Boolean.parseBoolean(env.getProperty(propName))) {
                    enabled = false;
                    break;
                }
            }
        }

        if (enabled) {
            enabled = ClassUtils.isPresent(SPRING_SEC_CLASS_NAME, ctx.getClassLoader());
        }

        return enabled;
    }
 
Example 3
Project: Lyrebird   File: Twitter4JComponents.java   View source code 5 votes vote down vote up
@Bean
public twitter4j.conf.Configuration configuration(final Environment environment) {
    final ConfigurationBuilder cb = new ConfigurationBuilder();
    final String consumerKey = environment.getProperty("twitter.consumerKey");
    final String consumerSecret = environment.getProperty("twitter.consumerSecret");
    cb.setOAuthConsumerSecret(consumerSecret);
    cb.setOAuthConsumerKey(consumerKey);
    return cb.build();
}
 
Example 4
Project: xm-ms-balance   File: DatabaseConfiguration.java   View source code 5 votes vote down vote up
public DatabaseConfiguration(Environment env,
                             JpaProperties jpaProperties,
                             TenantListRepository tenantListRepository) {
    this.env = env;
    this.jpaProperties = jpaProperties;
    this.tenantListRepository = tenantListRepository;
}
 
Example 5
Project: Microservices-with-JHipster-and-Spring-Boot   File: BlogApp.java   View source code 5 votes vote down vote up
/**
 * Main method, used to run the application.
 *
 * @param args the command line arguments
 * @throws UnknownHostException if the local host name could not be resolved into an address
 */
public static void main(String[] args) throws UnknownHostException {
    SpringApplication app = new SpringApplication(BlogApp.class);
    DefaultProfileUtil.addDefaultProfile(app);
    Environment env = app.run(args).getEnvironment();
    String protocol = "http";
    if (env.getProperty("server.ssl.key-store") != null) {
        protocol = "https";
    }
    log.info("\n----------------------------------------------------------\n\t" +
            "Application '{}' is running! Access URLs:\n\t" +
            "Local: \t\t{}://localhost:{}\n\t" +
            "External: \t{}://{}:{}\n\t" +
            "Profile(s): \t{}\n----------------------------------------------------------",
        env.getProperty("spring.application.name"),
        protocol,
        env.getProperty("server.port"),
        protocol,
        InetAddress.getLocalHost().getHostAddress(),
        env.getProperty("server.port"),
        env.getActiveProfiles());

    String configServerStatus = env.getProperty("configserver.status");
    log.info("\n----------------------------------------------------------\n\t" +
            "Config Server: \t{}\n----------------------------------------------------------",
        configServerStatus == null ? "Not found or not setup for this application" : configServerStatus);
}
 
Example 6
Project: JavaStudy   File: App.java   View source code 5 votes vote down vote up
@Test
public void test(){
    ApplicationContext atc=new AnnotationConfigApplicationContext(SystemProperties.class);
    SystemPropertiesMap map=(SystemPropertiesMap)atc.getBean("systemPropertiesMap");
    PrinterUtils.printILog("SystemPropertiesMap toString:"+map.toString());

    Environment environment=(Environment)atc.getBean("environment");
    PrinterUtils.printILog("environment getBean password:"+environment.getProperty("password"));


}
 
Example 7
Project: users-service   File: UserController.java   View source code 5 votes vote down vote up
public UserController(Environment env,
                      MongoTemplate mongo,
                      DateService dates,
                      RandomService random,
                      EmailService email) {

    this.env    = requireNonNull(env);
    this.mongo  = requireNonNull(mongo);
    this.dates  = requireNonNull(dates);
    this.random = requireNonNull(random);
    this.email  = requireNonNull(email);
}
 
Example 8
Project: sshd-shell-spring-boot   File: SshSessionInstance.java   View source code 5 votes vote down vote up
@Override
public void start(org.apache.sshd.server.Environment env) throws IOException {
    terminalType = env.getEnv().get("TERM");
    sshThread = new Thread(this, "ssh-cli " + session.getSession().getIoSession()
            .getAttribute(Constants.USER));
    sshThread.start();
}
 
Example 9
Project: users-service   File: TokensPurgeService.java   View source code 5 votes vote down vote up
public TokensPurgeService(
        final DateService dates,
        final MongoTemplate mongo,
        final Environment env) {

    this.dates = requireNonNull(dates);
    this.mongo = requireNonNull(mongo);
    this.env   = requireNonNull(env);
}
 
Example 10
Project: spring-cloud-vault-connector   File: VaultConnectorBootstrapConfiguration.java   View source code 5 votes vote down vote up
public VaultConnectorBootstrapConfiguration(
		VaultConnectorGenericBackendProperties connectorVaultProperties,
		VaultGenericBackendProperties genericBackendProperties,
		Environment environment) {

	this.connectorVaultProperties = connectorVaultProperties;
	this.genericBackendProperties = genericBackendProperties;
	this.environment = environment;

	Cloud cloud;
	VaultServiceInfo vaultServiceInfo = null;

	try {
		CloudFactory cloudFactory = new CloudFactory();
		cloud = cloudFactory.getCloud();

		List<ServiceInfo> serviceInfos = cloud.getServiceInfos(VaultOperations.class);
		if (serviceInfos.size() == 1) {
			vaultServiceInfo = (VaultServiceInfo) serviceInfos.get(0);
		}
	}
	catch (CloudException e) {
		// not running in a Cloud environment
	}

	this.vaultServiceInfo = vaultServiceInfo;
}
 
Example 11
Project: OAuth-2.0-Cookbook   File: GoogleConfigurerAdapter.java   View source code 5 votes vote down vote up
@Override
public void addConnectionFactories(
		final ConnectionFactoryConfigurer configurer,
		final Environment environment) {
	final GoogleConnectionFactory factory = new GoogleConnectionFactory(
			this.properties.getAppId(), this.properties.getAppSecret());
	configurer.addConnectionFactory(factory);
}
 
Example 12
Project: spring-io   File: DefaultProfileUtil.java   View source code 5 votes vote down vote up
/**
 * Get the profiles that are applied else get default profiles.
 *
 * @param env spring environment
 * @return profiles
 */
public static String[] getActiveProfiles(Environment env) {
    String[] profiles = env.getActiveProfiles();
    if (profiles.length == 0) {
        return env.getDefaultProfiles();
    }
    return profiles;
}
 
Example 13
Project: cmeter   File: ClickHouseExporterAutoConfiguration.java   View source code 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public ClickHouseDataSource clickHouseDataSource(Environment environment,
                                                 ClickHouseProperties clickHouseProperties) {
    return new ClickHouseDataSource(
            environment.getProperty("clickhouse.metrics.datasource.url", CLICKHOUSE_JDBC_URL),
            clickHouseProperties);
}
 
Example 14
Project: spring-io   File: GatewayApp.java   View source code 5 votes vote down vote up
/**
 * Main method, used to run the application.
 *
 * @param args the command line arguments
 * @throws UnknownHostException if the local host name could not be resolved into an address
 */
public static void main(String[] args) throws UnknownHostException {
    SpringApplication app = new SpringApplication(GatewayApp.class);
    DefaultProfileUtil.addDefaultProfile(app);
    Environment env = app.run(args).getEnvironment();
    String protocol = "http";
    if (env.getProperty("server.ssl.key-store") != null) {
        protocol = "https";
    }
    log.info("\n----------------------------------------------------------\n\t" +
            "Application '{}' is running! Access URLs:\n\t" +
            "Local: \t\t{}://localhost:{}\n\t" +
            "External: \t{}://{}:{}\n\t" +
            "Profile(s): \t{}\n----------------------------------------------------------",
        env.getProperty("spring.application.name"),
        protocol,
        env.getProperty("server.port"),
        protocol,
        InetAddress.getLocalHost().getHostAddress(),
        env.getProperty("server.port"),
        env.getActiveProfiles());

    String configServerStatus = env.getProperty("configserver.status");
    log.info("\n----------------------------------------------------------\n\t" +
            "Config Server: \t{}\n----------------------------------------------------------",
        configServerStatus == null ? "Not found or not setup for this application" : configServerStatus);
}
 
Example 15
Project: spring-test-examples   File: TestPropertyTest.java   View source code 5 votes vote down vote up
@Override
public void setEnvironment(Environment environment) {
  this.environment = environment;
  Map<String, Object> systemEnvironment = ((ConfigurableEnvironment) environment).getSystemEnvironment();
  System.out.println("=== System Environment ===");
  System.out.println(getMapString(systemEnvironment));
  System.out.println();

  System.out.println("=== Java System Properties ===");
  Map<String, Object> systemProperties = ((ConfigurableEnvironment) environment).getSystemProperties();
  System.out.println(getMapString(systemProperties));
}
 
Example 16
Project: my-postgres-broker   File: PostgresConfig.java   View source code 5 votes vote down vote up
@Bean
public DataSource datasource(Environment env) {
    PGPoolingDataSource source = new PGPoolingDataSource();
    source.setServerName(env.getProperty(POSTGRES_HOST_KEY));
    source.setDatabaseName(env.getProperty(POSTGRES_DB));
    source.setUser(env.getProperty(POSTGRES_USER));
    source.setPassword(env.getProperty(POSTGRES_PASSWORD));
    return source;
}
 
Example 17
Project: artifactory-resource   File: SystemInput.java   View source code 5 votes vote down vote up
protected SystemInput(Environment environment, SystemStreams systemStreams,
		ObjectMapper objectMapper, long timeout) {
	this.environment = environment;
	this.systemStreams = systemStreams;
	this.objectMapper = objectMapper;
	this.timeout = timeout;
}
 
Example 18
Project: Armory   File: DefaultProfileUtil.java   View source code 5 votes vote down vote up
/**
 * Get the profiles that are applied else get default profiles.
 */
public static String[] getActiveProfiles(Environment env) {
    String[] profiles = env.getActiveProfiles();
    if (profiles.length == 0) {
        return env.getDefaultProfiles();
    }
    return profiles;
}
 
Example 19
Project: shoucang   File: Application.java   View source code 5 votes vote down vote up
/**
 * Main method, used to run the application.
 */
public static void main(String[] args) throws UnknownHostException {
    SpringApplication app = new SpringApplication(Application.class);
    SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
    addDefaultProfile(app, source);
    Environment env = app.run(args).getEnvironment();
    log.info("Access URLs:\n----------------------------------------------------------\n\t" +
            "Local: \t\thttp://127.0.0.1:{}\n\t" +
            "External: \thttp://{}:{}\n----------------------------------------------------------",
        env.getProperty("server.port"),
        InetAddress.getLocalHost().getHostAddress(),
        env.getProperty("server.port"));

}
 
Example 20
Project: email-service   File: SenderService.java   View source code 5 votes vote down vote up
SenderService(MongoTemplate mongo,
                     RenderService renderer,
                     Environment env) {

    this.mongo    = requireNonNull(mongo);
    this.renderer = requireNonNull(renderer);
    this.env      = requireNonNull(env);
    this.mailgun  = new RestTemplate();
}
 
Example 21
Project: azeroth   File: EnvironmentHelper.java   View source code 5 votes vote down vote up
public static String getProperty(String key) {
    if (environment == null) {
        synchronized (EnvironmentHelper.class) {
            environment = InstanceFactory.getInstance(Environment.class);
        }
    }
    return environment.getProperty(key);
}
 
Example 22
Project: ColorConverter   File: Configuration.java   View source code 5 votes vote down vote up
private static Integer getIntegerSetting(Environment environment, String settingName) {
	Integer result = null;
	String ptyValue = environment.getProperty(settingName);
	if (ptyValue != null && !ptyValue.isEmpty()) {
		try {
			result = Integer.parseInt(ptyValue);
		} catch (NumberFormatException nfe) {
			// swallow
		}
	}
	return result;
}
 
Example 23
Project: xm-ms-entity   File: EntityApp.java   View source code 5 votes vote down vote up
/**
 * Main method, used to run the application.
 *
 * @param args the command line arguments
 * @throws UnknownHostException if the local host name could not be resolved into an address
 */
public static void main(String[] args) throws UnknownHostException {

    MDCUtil.put();

    SpringApplication app = new SpringApplication(EntityApp.class);
    DefaultProfileUtil.addDefaultProfile(app);
    Environment env = app.run(args).getEnvironment();
    String protocol = "http";
    if (env.getProperty("server.ssl.key-store") != null) {
        protocol = "https";
    }
    log.info("\n----------------------------------------------------------\n\t"
            + "Application '{}' is running! Access URLs:\n\t"
            + "Local: \t\t{}://localhost:{}\n\t"
            + "External: \t{}://{}:{}\n\t"
            + "Profile(s): \t{}\n----------------------------------------------------------",
        env.getProperty("spring.application.name"),
        protocol,
        env.getProperty("server.port"),
        protocol,
        InetAddress.getLocalHost().getHostAddress(),
        env.getProperty("server.port"),
        env.getActiveProfiles());

    String configServerStatus = env.getProperty("configserver.status");
    log.info("\n----------------------------------------------------------\n\t"
            + "Config Server: \t{}\n----------------------------------------------------------",
        configServerStatus == null ? "Not found or not setup for this application" : configServerStatus);
}
 
Example 24
Project: FCat   File: SwaggerConfiguration.java   View source code 5 votes vote down vote up
@Override
public void setEnvironment(Environment environment) {
	this.propertyResolver = new RelaxedPropertyResolver(environment, null);
	this.basePackage = propertyResolver.getProperty("swagger.basepackage");
	this.creatName = propertyResolver.getProperty("swagger.service.developer");
	this.serviceName = propertyResolver.getProperty("swagger.service.name");
	this.description = propertyResolver.getProperty("swagger.service.description");
}
 
Example 25
Project: codemotion-2017-taller-de-jhipster   File: DefaultProfileUtil.java   View source code 5 votes vote down vote up
/**
 * Get the profiles that are applied else get default profiles.
 *
 * @param env spring environment
 * @return profiles
 */
public static String[] getActiveProfiles(Environment env) {
    String[] profiles = env.getActiveProfiles();
    if (profiles.length == 0) {
        return env.getDefaultProfiles();
    }
    return profiles;
}
 
Example 26
Project: cas-5.1.0   File: CasCoreBootstrapStandaloneConfiguration.java   View source code 5 votes vote down vote up
private void loadEmbeddedYamlOverriddenProperties(final Properties props, final Environment environment) {
    final Resource resource = resourceLoader.getResource("classpath:/application.yml");
    if (resource != null && resource.exists()) {
        final Map pp = loadYamlProperties(resource);
        if (pp.isEmpty()) {
            LOGGER.debug("No properties were located inside [{}]", resource);
        } else {
            LOGGER.debug("Found settings [{}] in YAML file [{}]", pp.keySet(), resource);
            props.putAll(decryptProperties(pp));
        }
    }
}
 
Example 27
Project: spring-zeebe   File: ZeebeBrokerConfiguration.java   View source code 5 votes vote down vote up
@Bean
public ConfigurationManager configurationManager(final Environment environment)
{
    final Optional<String> tomlFile = tomlFileFromEnv.apply(environment);

    log.info("building broker from tomlFile={}", tomlFile);

    return new ConfigurationManagerImpl(tomlFile.orElse(null));
}
 
Example 28
Project: happylifeplat-transaction   File: RecoverConfiguration.java   View source code 4 votes vote down vote up
@Autowired
public JdbcRecoverConfiguration(Environment env) {
    this.env = env;
}
 
Example 29
Project: spring-configuration-support   File: SpringConfigurationSupportAutoConfiguration.java   View source code 4 votes vote down vote up
@Bean(name = "databaseConfiguration")
public DaoConfigurationPropertiesFactoryBean databaseConfigFactory(ConfigurationDao configurationDao, Environment environment) throws Exception {
	return new DaoConfigurationPropertiesFactoryBean(configurationDao, environment.getActiveProfiles());
}
 
Example 30
Project: spring-configuration-support   File: PropertiesConfig.java   View source code 4 votes vote down vote up
@Bean(name = "dbProps")
public DaoConfigurationPropertiesFactoryBean databaseConfigFactory(ConfigurationDao configurationDao, Environment environment) throws Exception {
	return new DaoConfigurationPropertiesFactoryBean(configurationDao, environment.getActiveProfiles(), "*");
}
 
Example 31
Project: happylifeplat-transaction   File: AdminConfiguration.java   View source code 4 votes vote down vote up
@Autowired
public RedisConfiguration(Environment env) {
    this.env = env;
}
 
Example 32
Project: spring-io   File: GatewayApp.java   View source code 4 votes vote down vote up
public GatewayApp(Environment env) {
    this.env = env;
}
 
Example 33
Project: Code4Health-Platform   File: CacheConfiguration.java   View source code 4 votes vote down vote up
public CacheConfiguration(Environment env) {
    this.env = env;
}
 
Example 34
Project: xm-ms-entity   File: CacheConfiguration.java   View source code 4 votes vote down vote up
public CacheConfiguration(Environment env) {
    this.env = env;
}
 
Example 35
Project: EsperIoT   File: MqttClientConfig.java   View source code 4 votes vote down vote up
@Override
public void setEnvironment(Environment environment) {
    this.propertyResolver = new RelaxedPropertyResolver(environment, "mqtt.");
}
 
Example 36
Project: xm-uaa   File: UaaApp.java   View source code 4 votes vote down vote up
public UaaApp(Environment env) {
    this.env = env;
}
 
Example 37
Project: xm-uaa   File: ProfileInfoResource.java   View source code 4 votes vote down vote up
public ProfileInfoResource(Environment env, JHipsterProperties jHipsterProperties) {
    this.env = env;
    this.jHipsterProperties = jHipsterProperties;
}
 
Example 38
Project: SpringMicroservice   File: Application.java   View source code 4 votes vote down vote up
@Autowired
GreetingController(Environment env){
	this.env = env;
}
 
Example 39
Project: RoboInsta   File: LoggingAspect.java   View source code 4 votes vote down vote up
public LoggingAspect(Environment env) {
    this.env = env;
}
 
Example 40
Project: qualitoast   File: DatabaseConfiguration.java   View source code 4 votes vote down vote up
public DatabaseConfiguration(Environment env) {
    this.env = env;
}