use of org.springframework.core.env.Environment in project jhipster-sample-app-websocket by jhipster.
the class JhipsterWebsocketSampleApplicationApp method main.
/**
* Main method, used to run the application.
*
* @param args the command line arguments
*/
public static void main(String[] args) {
SpringApplication app = new SpringApplication(JhipsterWebsocketSampleApplicationApp.class);
DefaultProfileUtil.addDefaultProfile(app);
Environment env = app.run(args).getEnvironment();
String protocol = "http";
if (env.getProperty("server.ssl.key-store") != null) {
protocol = "https";
}
String hostAddress = "localhost";
try {
hostAddress = InetAddress.getLocalHost().getHostAddress();
} catch (Exception e) {
log.warn("The host name could not be determined, using `localhost` as fallback");
}
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, hostAddress, env.getProperty("server.port"), env.getActiveProfiles());
}
use of org.springframework.core.env.Environment in project jhipster-sample-app-oauth2 by jhipster.
the class JhipsterOauth2SampleApplicationApp method main.
/**
* Main method, used to run the application.
*
* @param args the command line arguments
*/
public static void main(String[] args) {
SpringApplication app = new SpringApplication(JhipsterOauth2SampleApplicationApp.class);
DefaultProfileUtil.addDefaultProfile(app);
Environment env = app.run(args).getEnvironment();
String protocol = "http";
if (env.getProperty("server.ssl.key-store") != null) {
protocol = "https";
}
String hostAddress = "localhost";
try {
hostAddress = InetAddress.getLocalHost().getHostAddress();
} catch (Exception e) {
log.warn("The host name could not be determined, using `localhost` as fallback");
}
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, hostAddress, env.getProperty("server.port"), env.getActiveProfiles());
}
use of org.springframework.core.env.Environment in project hello-world by haoziapple.
the class JhApp method main.
/**
* 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(JhApp.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());
}
use of org.springframework.core.env.Environment in project jhipster-registry by jhipster.
the class ProfileInfoResourceTest method setup.
@Before
public void setup() {
Environment env = Mockito.mock(Environment.class);
JHipsterProperties prop = Mockito.mock(JHipsterProperties.class);
JHipsterProperties.Ribbon ribbon = Mockito.mock(JHipsterProperties.Ribbon.class);
ProfileInfoResource profileInfoResource = new ProfileInfoResource(env, prop);
this.mock = MockMvcBuilders.standaloneSetup(profileInfoResource).build();
Mockito.when(env.getActiveProfiles()).thenReturn(profiles);
Mockito.when(prop.getRibbon()).thenReturn(ribbon);
}
use of org.springframework.core.env.Environment in project herd by FINRAOS.
the class AppSpringModuleConfig method log4jConfigurer.
/**
* The Log4J overridable configurer that will handle our Log4J initialization for the herd application.
* <p/>
* IMPORTANT: Ensure this method is static since the returned Log4jOverridableConfigurer is a bean factory post processor (BFPP). If it weren't static,
* autowiring and injection on this @Configuration class won't work due to lifecycle issues. See "Bootstrapping" comment in @Bean annotation for more
* details.
*
* @return the Log4J overridable configurer.
*/
@Bean
public static Log4jOverridableConfigurer log4jConfigurer() {
// Access the environment using the application context holder since we're in a static method that doesn't have access to the environment in any
// other way.
Environment environment = ApplicationContextHolder.getApplicationContext().getEnvironment();
// Create the Log4J configurer.
Log4jOverridableConfigurer log4jConfigurer = new Log4jOverridableConfigurer();
// This is the primary database override location (if present). An entry needs to be present in the database at application startup for this
// configuration to be used.
log4jConfigurer.setDataSource(DaoSpringModuleConfig.getHerdDataSource());
log4jConfigurer.setTableName(ConfigurationEntity.TABLE_NAME);
log4jConfigurer.setSelectColumn(ConfigurationEntity.COLUMN_VALUE_CLOB);
log4jConfigurer.setWhereColumn(ConfigurationEntity.COLUMN_KEY);
log4jConfigurer.setWhereValue(ConfigurationValue.LOG4J_OVERRIDE_CONFIGURATION.getKey());
// This is the secondary override location (if present and if the primary location isn't present). This resource needs to be present at application
// startup for this configuration to be used.
log4jConfigurer.setOverrideResourceLocation(ConfigurationHelper.getProperty(ConfigurationValue.LOG4J_OVERRIDE_RESOURCE_LOCATION, environment));
// This is the default fallback location which is bundled in the WAR and should always be present in case the override locations aren't present.
// Note that the herd-log4j.xml file must be in the herd-war project so it is accessible on the classpath as a file. Placing it within another
// project's JAR will result in the resource not being found as a "file".
log4jConfigurer.setDefaultResourceLocation("classpath:herd-log4j.xml");
// Return the Log4J configurer.
return log4jConfigurer;
}
Aggregations