示例#1
0
 /**
  * Initializes gestionDemandes.
  *
  * <p>Spring profiles can be configured with a program arguments
  * --spring.profiles.active=your-active-profile
  *
  * <p>
  *
  * <p>You can find more information on how profiles work with JHipster on <a
  * href="http://jhipster.github.io/profiles.html">http://jhipster.github.io/profiles.html</a>.
  */
 @PostConstruct
 public void initApplication() throws IOException {
   if (env.getActiveProfiles().length == 0) {
     log.warn("No Spring profile configured, running with default configuration");
   } else {
     log.info("Running with Spring profile(s) : {}", Arrays.toString(env.getActiveProfiles()));
     Collection<String> activeProfiles = Arrays.asList(env.getActiveProfiles());
     if (activeProfiles.contains(Constants.SPRING_PROFILE_DEVELOPMENT)
         && activeProfiles.contains(Constants.SPRING_PROFILE_PRODUCTION)) {
       log.error(
           "You have misconfigured your application! "
               + "It should not run with both the 'dev' and 'prod' profiles at the same time.");
     }
     if (activeProfiles.contains(Constants.SPRING_PROFILE_PRODUCTION)
         && activeProfiles.contains(Constants.SPRING_PROFILE_FAST)) {
       log.error(
           "You have misconfigured your application! "
               + "It should not run with both the 'prod' and 'fast' profiles at the same time.");
     }
     if (activeProfiles.contains(Constants.SPRING_PROFILE_DEVELOPMENT)
         && activeProfiles.contains(Constants.SPRING_PROFILE_CLOUD)) {
       log.error(
           "You have misconfigured your application! "
               + "It should not run with both the 'dev' and 'cloud' profiles at the same time.");
     }
   }
 }
示例#2
0
  /**
   * Initializes swank.
   *
   * <p>Spring profiles can be configured with a program arguments
   * --spring.profiles.active=your-active-profile
   *
   * <p>
   *
   * <p>You can find more information on how profiles work with JHipster on <a
   * href="http://jhipster.github.io/profiles.html">http://jhipster.github.io/profiles.html</a>.
   */
  @PostConstruct
  public void initApplication() throws IOException {

    /*        System.out.printf("This is the classpath: %s %n",
        System.getProperty("java.class.path"));
    Set<String> propNames = new TreeSet<String>(System.getProperties().stringPropertyNames());
    for (String propertyName : propNames) {
        System.out.printf("%s is %s %n",
            propertyName,
            System.getProperty(propertyName));
    }*/

    if (env.getActiveProfiles().length == 0) {
      log.warn("No Spring profile configured, running with default configuration");
    } else {
      log.info("Running with Spring profile(s) : {}", Arrays.toString(env.getActiveProfiles()));
      Collection<String> activeProfiles = Arrays.asList(env.getActiveProfiles());
      if (activeProfiles.contains("dev") && activeProfiles.contains("prod")) {
        log.error(
            "You have misconfigured your application! "
                + "It should not run with both the 'dev' and 'prod' profiles at the same time.");
      }
      if (activeProfiles.contains("prod") && activeProfiles.contains("fast")) {
        log.error(
            "You have misconfigured your application! "
                + "It should not run with both the 'prod' and 'fast' profiles at the same time.");
      }
      if (activeProfiles.contains("dev") && activeProfiles.contains("cloud")) {
        log.error(
            "You have misconfigured your application! "
                + "It should not run with both the 'dev' and 'cloud' profiles at the same time.");
      }
    }
  }
 private static String getMessage(
     EmbeddedDatabaseConnection connection, Environment environment, String property) {
   StringBuilder message = new StringBuilder();
   message.append(
       "Cannot determine embedded database "
           + property
           + " for database type "
           + connection
           + ". ");
   message.append(
       "If you want an embedded database please put a supported " + "one on the classpath. ");
   message.append(
       "If you have database settings to be loaded from a "
           + "particular profile you may need to active it");
   if (environment != null) {
     String[] profiles = environment.getActiveProfiles();
     if (ObjectUtils.isEmpty(profiles)) {
       message.append(" (no profiles are currently active)");
     } else {
       message.append(
           " (the profiles \""
               + StringUtils.arrayToCommaDelimitedString(environment.getActiveProfiles())
               + "\" are currently active)");
     }
   }
   message.append(".");
   return message.toString();
 }
 @PostConstruct
 public void initApplication() throws IOException {
   if (env.getActiveProfiles().length == 0) {
     LOGGER.warn("No Spring profile configured, running with default configuration");
   } else {
     LOGGER.info("Running with Spring profile(s) : {}", Arrays.toString(env.getActiveProfiles()));
   }
 }
  /**
   * Application context custom initialization. Spring profiles can be configured with a system
   * property -Dspring.profiles.active=test
   */
  @PostConstruct
  public void customInit() {

    logger.debug("Looking for Spring active profiles...");
    if (env.getActiveProfiles().length == 0) {
      logger.info("No Spring profile configured, running with default configuration.");
    } else {
      logger.info("Detected Spring profiles: {}", Arrays.asList(env.getActiveProfiles()));
    }
  }
示例#6
0
 @Override
 public void onStartup(ServletContext servletContext) throws ServletException {
   if (env.getActiveProfiles().length != 0) {
     log.info(
         "Web application configuration, using profiles: {}",
         Arrays.toString(env.getActiveProfiles()));
   }
   EnumSet<DispatcherType> disps =
       EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC);
   initMetrics(servletContext, disps);
   if (env.acceptsProfiles(Constants.SPRING_PROFILE_PRODUCTION)) {
     initCachingHttpHeadersFilter(servletContext, disps);
   }
   log.info("Web application fully configured");
 }
  @Bean(destroyMethod = "close")
  @ConditionalOnExpression(
      "#{!environment.acceptsProfiles('cloud') && !environment.acceptsProfiles('heroku')}")
  public DataSource dataSource(
      DataSourceProperties dataSourceProperties, JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Datasource");
    if (dataSourceProperties.getUrl() == null) {
      log.error(
          "Your database connection pool configuration is incorrect! The application"
              + " cannot start. Please check your Spring profile, current profiles are: {}",
          Arrays.toString(env.getActiveProfiles()));

      throw new ApplicationContextException("Database connection pool is not configured correctly");
    }
    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName(dataSourceProperties.getDriverClassName());
    config.addDataSourceProperty("url", dataSourceProperties.getUrl());
    if (dataSourceProperties.getUsername() != null) {
      config.addDataSourceProperty("user", dataSourceProperties.getUsername());
    } else {
      config.addDataSourceProperty("user", ""); // HikariCP doesn't allow null user
    }
    if (dataSourceProperties.getPassword() != null) {
      config.addDataSourceProperty("password", dataSourceProperties.getPassword());
    } else {
      config.addDataSourceProperty("password", ""); // HikariCP doesn't allow null password
    }

    if (metricRegistry != null) {
      config.setMetricRegistry(metricRegistry);
    }
    return new HikariDataSource(config);
  }
  @Bean
  public DataSource dataSource() {
    log.debug("Configuring Datasource");
    if (propertyResolver.getProperty("url") == null
        && propertyResolver.getProperty("databaseName") == null) {
      log.error(
          "Your database connection pool configuration is incorrect! The application"
              + "cannot start. Please check your Spring profile, current profiles are: {}",
          Arrays.toString(environment.getActiveProfiles()));

      throw new ApplicationContextException("Database connection pool is not configured correctly");
    }
    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName(propertyResolver.getProperty("dataSourceClassName"));
    if (propertyResolver.getProperty("url") == null
        || "".equals(propertyResolver.getProperty("url"))) {
      config.addDataSourceProperty("databaseName", propertyResolver.getProperty("databaseName"));
      config.addDataSourceProperty("serverName", propertyResolver.getProperty("serverName"));
    } else {
      config.addDataSourceProperty("url", propertyResolver.getProperty("url"));
    }
    config.addDataSourceProperty("user", propertyResolver.getProperty("username"));
    config.addDataSourceProperty("password", propertyResolver.getProperty("password"));
    return new HikariDataSource(config);
  }
 @Bean(destroyMethod = "close")
 public DataSource dataSource() {
   String dbUrl, username, password;
   List<String> activeProfiles = Arrays.asList(environment.getActiveProfiles());
   if (activeProfiles.contains("production")) {
     URI dbUri;
     try {
       dbUri = new URI(datasourcePropertyResolver.getProperty("heroku-uri"));
     } catch (URISyntaxException e) {
       throw new ApplicationContextException(
           "Heroku database connection pool is not configured correctly");
     }
     dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ":" + dbUri.getPort() + dbUri.getPath();
     username = dbUri.getUserInfo().split(":")[0];
     password = dbUri.getUserInfo().split(":")[1];
   } else {
     dbUrl = datasourcePropertyResolver.getProperty("url");
     username = datasourcePropertyResolver.getProperty("username");
     password = datasourcePropertyResolver.getProperty("password");
   }
   DataSource dataSource = new DataSource();
   dataSource.setDriverClassName(datasourcePropertyResolver.getProperty("driver-class-name"));
   dataSource.setUrl(dbUrl);
   dataSource.setUsername(username);
   dataSource.setPassword(password);
   return dataSource;
 }
  @Bean(destroyMethod = "shutdown")
  @ConditionalOnExpression(
      "#{!environment.acceptsProfiles('cloud') && !environment.acceptsProfiles('heroku')}")
  public DataSource dataSource() {
    log.debug("Configuring Datasource");
    if (dataSourcePropertyResolver.getProperty("url") == null
        && dataSourcePropertyResolver.getProperty("databaseName") == null) {
      log.error(
          "Your database connection pool configuration is incorrect! The application"
              + " cannot start. Please check your Spring profile, current profiles are: {}",
          Arrays.toString(env.getActiveProfiles()));

      throw new ApplicationContextException("Database connection pool is not configured correctly");
    }
    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName(dataSourcePropertyResolver.getProperty("dataSourceClassName"));
    if (StringUtils.isEmpty(dataSourcePropertyResolver.getProperty("url"))) {
      config.addDataSourceProperty(
          "databaseName", dataSourcePropertyResolver.getProperty("databaseName"));
      config.addDataSourceProperty(
          "serverName", dataSourcePropertyResolver.getProperty("serverName"));
    } else {
      config.addDataSourceProperty("url", dataSourcePropertyResolver.getProperty("url"));
    }
    config.addDataSourceProperty("user", dataSourcePropertyResolver.getProperty("username"));
    config.addDataSourceProperty("password", dataSourcePropertyResolver.getProperty("password"));

    if (metricRegistry != null) {
      config.setMetricRegistry(metricRegistry);
    }
    return new HikariDataSource(config);
  }
 @RequestMapping(
     value = "/profile-info",
     method = RequestMethod.GET,
     produces = MediaType.APPLICATION_JSON_VALUE)
 public ProfileInfoResponse getActiveProfiles() {
   return new ProfileInfoResponse(env.getActiveProfiles(), getRibbonEnv());
 }
 /**
  * Initializes jhipsterNoCacheSampleApplication.
  *
  * <p>Spring profiles can be configured with a program arguments
  * --spring.profiles.active=your-active-profile
  *
  * <p>You can find more information on how profiles work with JHipster on <a
  * href="http://jhipster.github.io/profiles/">http://jhipster.github.io/profiles/</a>.
  */
 @PostConstruct
 public void initApplication() {
   log.info("Running with Spring profile(s) : {}", Arrays.toString(env.getActiveProfiles()));
   Collection<String> activeProfiles = Arrays.asList(env.getActiveProfiles());
   if (activeProfiles.contains(Constants.SPRING_PROFILE_DEVELOPMENT)
       && activeProfiles.contains(Constants.SPRING_PROFILE_PRODUCTION)) {
     log.error(
         "You have misconfigured your application! It should not run "
             + "with both the 'dev' and 'prod' profiles at the same time.");
   }
   if (activeProfiles.contains(Constants.SPRING_PROFILE_DEVELOPMENT)
       && activeProfiles.contains(Constants.SPRING_PROFILE_CLOUD)) {
     log.error(
         "You have misconfigured your application! It should not"
             + "run with both the 'dev' and 'cloud' profiles at the same time.");
   }
 }
  private String getRibbonEnv() {
    String[] activeProfiles = env.getActiveProfiles();
    String[] displayOnActiveProfiles = jHipsterProperties.getRibbon().getDisplayOnActiveProfiles();

    if (displayOnActiveProfiles == null) {
      return null;
    }

    List<String> ribbonProfiles = new ArrayList<>(Arrays.asList(displayOnActiveProfiles));
    List<String> springBootProfiles = Arrays.asList(activeProfiles);
    ribbonProfiles.retainAll(springBootProfiles);

    if (ribbonProfiles.size() > 0) {
      return ribbonProfiles.get(0);
    }
    return null;
  }
  @Bean(destroyMethod = "close")
  @ConditionalOnExpression(
      "#{!environment.acceptsProfiles('cloud') && !environment.acceptsProfiles('heroku')}")
  public DataSource dataSource(
      DataSourceProperties dataSourceProperties, JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Datasource");
    if (dataSourceProperties.getUrl() == null) {
      log.error(
          "Your database connection pool configuration is incorrect! The application"
              + " cannot start. Please check your Spring profile, current profiles are: {}",
          Arrays.toString(env.getActiveProfiles()));

      throw new ApplicationContextException("Database connection pool is not configured correctly");
    }
    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName(dataSourceProperties.getDriverClassName());
    config.addDataSourceProperty("url", dataSourceProperties.getUrl());
    if (dataSourceProperties.getUsername() != null) {
      config.addDataSourceProperty("user", dataSourceProperties.getUsername());
    } else {
      config.addDataSourceProperty("user", ""); // HikariCP doesn't allow null user
    }
    if (dataSourceProperties.getPassword() != null) {
      config.addDataSourceProperty("password", dataSourceProperties.getPassword());
    } else {
      config.addDataSourceProperty("password", ""); // HikariCP doesn't allow null password
    }

    // MySQL optimizations, see https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
    if ("com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
        .equals(dataSourceProperties.getDriverClassName())) {
      config.addDataSourceProperty(
          "cachePrepStmts", jHipsterProperties.getDatasource().isCachePrepStmts());
      config.addDataSourceProperty(
          "prepStmtCacheSize", jHipsterProperties.getDatasource().getPrepStmtCacheSize());
      config.addDataSourceProperty(
          "prepStmtCacheSqlLimit", jHipsterProperties.getDatasource().getPrepStmtCacheSqlLimit());
    }
    if (metricRegistry != null) {
      config.setMetricRegistry(metricRegistry);
    }
    return new HikariDataSource(config);
  }
示例#15
0
  @Bean(destroyMethod = "shutdown")
  @ConditionalOnExpression(
      "#{!environment.acceptsProfiles('cloud') && !environment.acceptsProfiles('heroku')}")
  public DataSource dataSource() {
    log.debug("Configuring Datasource");
    if (dataSourcePropertyResolver.getProperty("url") == null
        && dataSourcePropertyResolver.getProperty("databaseName") == null) {
      log.error(
          "Your database connection pool configuration is incorrect! The application"
              + " cannot start. Please check your Spring profile, current profiles are: {}",
          Arrays.toString(env.getActiveProfiles()));

      throw new ApplicationContextException("Database connection pool is not configured correctly");
    }
    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName(dataSourcePropertyResolver.getProperty("dataSourceClassName"));
    if (StringUtils.isEmpty(dataSourcePropertyResolver.getProperty("url"))) {
      config.addDataSourceProperty(
          "databaseName", dataSourcePropertyResolver.getProperty("databaseName"));
      config.addDataSourceProperty(
          "serverName", dataSourcePropertyResolver.getProperty("serverName"));
    } else {
      config.addDataSourceProperty("url", dataSourcePropertyResolver.getProperty("url"));
    }
    config.addDataSourceProperty("user", dataSourcePropertyResolver.getProperty("username"));
    config.addDataSourceProperty("password", dataSourcePropertyResolver.getProperty("password"));

    // MySQL optimizations, see https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
    if ("com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
        .equals(dataSourcePropertyResolver.getProperty("dataSourceClassName"))) {
      config.addDataSourceProperty(
          "cachePrepStmts", dataSourcePropertyResolver.getProperty("cachePrepStmts", "true"));
      config.addDataSourceProperty(
          "prepStmtCacheSize", dataSourcePropertyResolver.getProperty("prepStmtCacheSize", "250"));
      config.addDataSourceProperty(
          "prepStmtCacheSqlLimit",
          dataSourcePropertyResolver.getProperty("prepStmtCacheSqlLimit", "2048"));
    }
    if (metricRegistry != null) {
      config.setMetricRegistry(metricRegistry);
    }
    return new HikariDataSource(config);
  }
示例#16
0
 @Override
 public void onStartup(ServletContext servletContext) throws ServletException {
   log.info(
       "Web application configuration, using profiles: {}",
       Arrays.toString(env.getActiveProfiles()));
   EnumSet<DispatcherType> disps =
       EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC);
   if (!env.acceptsProfiles(Constants.SPRING_PROFILE_FAST)) {
     initMetrics(servletContext, disps);
   }
   if (env.acceptsProfiles(Constants.SPRING_PROFILE_PRODUCTION)) {
     initCachingHttpHeadersFilter(servletContext, disps);
     initStaticResourcesProductionFilter(servletContext, disps);
     initGzipFilter(servletContext, disps);
   }
   if (env.acceptsProfiles(Constants.SPRING_PROFILE_DEVELOPMENT)) {
     initH2Console(servletContext);
   }
   log.info("Web application fully configured");
 }
  @Bean(destroyMethod = "shutDown")
  public PersistenceManager getPersistenceManager() {

    final List<String> activeProfiles = Arrays.asList(env.getActiveProfiles());
    boolean isProduction = activeProfiles.contains(Profiles.SPRING_PROFILE_PRODUCTION);
    PersistenceManagerFactory pmFactory =
        PersistenceManagerFactoryBuilder.builder(cluster)
            .withEntityPackages(UserEntity.class.getPackage().getName())
            .withDefaultReadConsistency(ConsistencyLevel.ONE)
            .withDefaultWriteConsistency(ConsistencyLevel.ONE)
            .withKeyspaceName(Schema.KEYSPACE)
            .withExecutorServiceMinThreadCount(5)
            .withExecutorServiceMaxThreadCount(10)
            .forceTableCreation(isProduction ? false : true)
            .build();

    final PersistenceManager pm = pmFactory.createPersistenceManager();

    pm.insert(
        UserEntity.fromModel(KILLRCHAT_USER),
        OptionsBuilder.ifNotExists()
            .lwtResultListener(
                new LWTResultListener() {
                  @Override
                  public void onSuccess() {
                    logger.info("Create new administration 'killrchat' account");
                  }

                  @Override
                  public void onError(LWTResult lwtResult) {
                    logger.debug("Administration 'killrchat' account already exists");
                  }
                }));

    return pm;
  }
 private boolean findProfile(String profileName) {
   return Arrays.asList(env.getActiveProfiles()).contains(profileName);
 }
 @Override
 public void setEnvironment(Environment environment) {
   if (Arrays.asList(environment.getActiveProfiles()).contains("strict")) {
     this.exceptionIfInvalid = true;
   }
 }