public JHipsterReloaderThread(
     ConfigurableApplicationContext applicationContext, Collection<Reloader> reloaders) {
   this.reloaders = reloaders;
   domainPackageName = applicationContext.getEnvironment().getProperty("hotReload.package.domain");
   dtoPackageName = applicationContext.getEnvironment().getProperty("hotReload.package.restdto");
   isStarted = true;
 }
 @Test
 public void propertySourceAnnotationWithName() throws Exception {
   SpringApplication application = new SpringApplication(WithPropertySourceAndName.class);
   application.setWebEnvironment(false);
   ConfigurableApplicationContext context = application.run();
   String property = context.getEnvironment().getProperty("the.property");
   assertThat(property, equalTo("fromspecificlocation"));
   assertThat(context.getEnvironment(), containsPropertySource("foo"));
   context.close();
 }
 @Test
 public void propertySourceAnnotationAndNonActiveProfile() throws Exception {
   SpringApplication application = new SpringApplication(WithPropertySourceAndProfile.class);
   application.setWebEnvironment(false);
   ConfigurableApplicationContext context = application.run();
   String property = context.getEnvironment().getProperty("my.property");
   assertThat(property, equalTo("fromapplicationproperties"));
   assertThat(
       context.getEnvironment(),
       not(containsPropertySource("classpath:" + "/enableprofile-myprofile.properties")));
   context.close();
 }
 @Test
 public void propertySourceAnnotationMultipleLocations() throws Exception {
   SpringApplication application =
       new SpringApplication(WithPropertySourceMultipleLocations.class);
   application.setWebEnvironment(false);
   ConfigurableApplicationContext context = application.run();
   String property = context.getEnvironment().getProperty("the.property");
   assertThat(property, equalTo("frommorepropertiesfile"));
   assertThat(
       context.getEnvironment(),
       containsPropertySource("class path resource " + "[specificlocation.properties]"));
   context.close();
 }
 @Test
 public void propertySourceAnnotationWithPlaceholder() throws Exception {
   EnvironmentTestUtils.addEnvironment(this.environment, "source.location:specificlocation");
   SpringApplication application = new SpringApplication(WithPropertySourcePlaceholders.class);
   application.setEnvironment(this.environment);
   application.setWebEnvironment(false);
   ConfigurableApplicationContext context = application.run();
   String property = context.getEnvironment().getProperty("the.property");
   assertThat(property, equalTo("fromspecificlocation"));
   assertThat(
       context.getEnvironment(),
       containsPropertySource("class path resource " + "[specificlocation.properties]"));
   context.close();
 }
 @Test
 public void propertySourceAnnotationInProfile() throws Exception {
   SpringApplication application = new SpringApplication(WithPropertySourceInProfile.class);
   application.setWebEnvironment(false);
   ConfigurableApplicationContext context = application.run("--spring.profiles.active=myprofile");
   String property = context.getEnvironment().getProperty("the.property");
   assertThat(property, equalTo("frompropertiesfile"));
   assertThat(
       context.getEnvironment(),
       containsPropertySource("class path resource " + "[enableprofile.properties]"));
   assertThat(
       context.getEnvironment(),
       not(containsPropertySource("classpath:/" + "enableprofile-myprofile.properties")));
   context.close();
 }
  /**
   * Register the classLoader and start a thread that will be used to monitor folders where classes
   * can be created.
   *
   * @param classLoader the classLoader of the application
   * @param ctx the spring application context
   */
  public static void register(ClassLoader classLoader, ConfigurableApplicationContext ctx) {
    try {
      Environment env = ctx.getEnvironment();

      // Load from env the list of folders to watch
      List<String> watchFolders = getWatchFolders(env);

      if (watchFolders.size() == 0) {
        log.warn(
            "SpringLoaded - No watched folders have been defined in the application-{profile}.yml. "
                + "We will use the default target/classes");
        watchFolders.add("target/classes");
      }

      final Thread thread =
          new Thread(new JHipsterFileSystemWatcher(watchFolders, ctx, classLoader));
      thread.setDaemon(true);
      thread.start();

      Runtime.getRuntime()
          .addShutdownHook(
              new Thread() {
                public void run() {
                  JHipsterFileSystemWatcher.isStarted = false;
                  try {
                    thread.join();
                  } catch (InterruptedException e) {
                    log.error("Failed during the JVM shutdown", e);
                  }
                }
              });
    } catch (Exception e) {
      log.error("Failed to start the watcher. New class will not be loaded.", e);
    }
  }
 @Before
 public void init() {
   ConfigurableApplicationContext context =
       new SpringApplicationBuilder(NativeEnvironmentRepositoryTests.class).web(false).run();
   this.repository = new NativeEnvironmentRepository(context.getEnvironment());
   this.repository.setVersion("myversion");
   context.close();
 }
Beispiel #9
0
 /** Update container log appender file name with container id */
 private void updateLoggerFilename() {
   Appender appender = Logger.getRootLogger().getAppender(LOG4J_FILE_APPENDER);
   if (appender instanceof RollingFileAppender) {
     String xdHome = context.getEnvironment().getProperty(XDPropertyKeys.XD_HOME);
     ((RollingFileAppender) appender)
         .setFile(new File(xdHome).getAbsolutePath() + "/logs/container-" + this.getId() + ".log");
     ((RollingFileAppender) appender).activateOptions();
   }
 }
    public static void register(ConfigurableApplicationContext ctx, ClassLoader classLoader) {
        Environment env = ctx.getEnvironment();

        if (env.getProperty("hotReload.enabled", Boolean.class, false)) {
            jHipsterReloaderThread = new JHipsterReloaderThread(ctx);
            JHipsterReloaderThread.register(jHipsterReloaderThread);
            JHipsterFileSystemWatcher.register(classLoader, ctx);
            Plugins.registerGlobalPlugin(new JHipsterPluginManagerReloadPlugin());
        }
    }
 public static void main(String[] args) {
   ConfigurableApplicationContext run = SpringApplication.run(Application.class, args);
   CompositePropertySource compositePropertySource =
       (CompositePropertySource) run.getEnvironment().getPropertySources().get("bootstrap");
   for (PropertySource<?> propertySource : compositePropertySource.getPropertySources()) {
     System.out.println("propertySource name: " + propertySource.getName());
     for (String name : ((EnumerablePropertySource<?>) propertySource).getPropertyNames()) {
       System.out.println(String.format("%s=%s", name, propertySource.getProperty(name)));
     }
   }
 }
Beispiel #12
0
  /**
   * Main class initializes the Spring Application Context and populates seed data using {@link
   * SeedDataService}.
   *
   * @param args Not used.
   */
  public static void main(String[] args) {
    Map<String, Object> props = new HashMap<String, Object>();
    props.put("redisPort", SocketUtils.findAvailableTcpPort());

    SpringApplication app = new SpringApplication(MainApp.class);
    app.setDefaultProperties(props);

    ConfigurableApplicationContext context = app.run(args);

    MapPropertySource propertySource = new MapPropertySource("ports", props);

    context.getEnvironment().getPropertySources().addFirst(propertySource);

    SeedDataService seedDataService = context.getBean(SeedDataService.class);
    seedDataService.populateSeedData();
  }
Beispiel #13
0
  protected static void mess() {
    //		System.setProperty("spring.profiles.active","foo");
    //		    	ConfigurableApplicationContext ctx =
    //		    			new
    // ClassPathXmlApplicationContext("classpath:/com/rooney/spring/spel/Spel-context.xml");

    // can we add appcontext.xml to a genericAppCtx and then add property sources, when call
    // refresh?
    ConfigurableApplicationContext ctx = new GenericApplicationContext();
    ConfigurableEnvironment environment = ctx.getEnvironment();

    MutablePropertySources sources = environment.getPropertySources();
    sources.addFirst(new MyPropertySource());

    System.out.println(ctx.getBean("stringBean"));
  }
Beispiel #14
0
 public static void main(String[] args) throws Exception {
   TrustAnyCertificate.setAlwaysTrust(true);
   context = SpringApplication.run(CloudUiApplication.class, args);
   System.out.println(context.getEnvironment().getProperty("server.port"));
 }
 @Override
 public void initialize(ConfigurableApplicationContext applicationContext) {
   ConfigurableEnvironment environment = applicationContext.getEnvironment();
   environment.setActiveProfiles("alarms-" + environment.getProperty("httpd.alarms.db.type"));
 }
 @Override
 public void initialize(ConfigurableApplicationContext applicationContext) {
   applicationContext.setId(getApplicationId(applicationContext.getEnvironment()));
 }