Example usage for org.springframework.core.env AbstractEnvironment ACTIVE_PROFILES_PROPERTY_NAME

List of usage examples for org.springframework.core.env AbstractEnvironment ACTIVE_PROFILES_PROPERTY_NAME

Introduction

In this page you can find the example usage for org.springframework.core.env AbstractEnvironment ACTIVE_PROFILES_PROPERTY_NAME.

Prototype

String ACTIVE_PROFILES_PROPERTY_NAME

To view the source code for org.springframework.core.env AbstractEnvironment ACTIVE_PROFILES_PROPERTY_NAME.

Click Source Link

Document

Name of property to set to specify active profiles: .

Usage

From source file:com.github.dactiv.fear.commons.test.JettyRunner.java

/**
 * ??/* w  ww.  ja  v a 2 s  .com*/
 */
public Server startServer() {
    System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, this.environment);
    Server server = new Server();
    // JVMJetty
    server.setStopAtShutdown(true);

    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    //  apache shiro  rememberMe ?cookie jetty  header buffer size ????
    connector.setResponseHeaderSize(8192);
    // ???Jetty??
    connector.setReuseAddress(false);
    server.setConnectors(new Connector[] { connector });

    WebAppContext webContext = new WebAppContext(webPath, contextPath);
    server.setHandler(webContext);

    try {

        server.start();
        LOGGER.info("Browse URL : http://localhost:" + port + contextPath);
        return server;
    } catch (Exception e) {
        LOGGER.error("jetty ?", e);
    }

    return null;
}

From source file:io.gravitee.management.war.WebAppInitializer.java

@Override
public void onStartup(ServletContext context) throws ServletException {
    // initialize
    initialize();//from w  w  w .  j a  v  a2 s  . co  m
    Properties prop = propertiesLoader.load();

    // REST configuration
    ServletRegistration.Dynamic servletRegistration = context.addServlet("REST",
            ServletContainer.class.getName());
    servletRegistration.addMapping("/management/*");
    servletRegistration.setLoadOnStartup(1);
    servletRegistration.setInitParameter("javax.ws.rs.Application", GraviteeApplication.class.getName());

    // Spring configuration
    System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME,
            prop.getProperty("security.type", "basic-auth"));
    context.addListener(new ContextLoaderListener());
    context.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
    context.setInitParameter("contextConfigLocation", RestConfiguration.class.getName());

    // Spring Security filter
    context.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class)
            .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, "/*");
}

From source file:io.gravitee.management.standalone.jetty.JettyEmbeddedContainer.java

@Override
protected void doStart() throws Exception {
    AbstractHandler noContentHandler = new NoContentOutputErrorHandler();
    // This part is needed to avoid WARN while starting container.
    noContentHandler.setServer(server);//from w ww  .jav a2 s  .  c o m
    server.addBean(noContentHandler);

    // Create the servlet context
    final ServletContextHandler context = new ServletContextHandler(server, "/management/*",
            ServletContextHandler.SESSIONS);

    // REST configuration
    final ServletHolder servletHolder = new ServletHolder(ServletContainer.class);
    servletHolder.setInitParameter("javax.ws.rs.Application", GraviteeApplication.class.getName());
    servletHolder.setInitOrder(0);
    context.addServlet(servletHolder, "/*");

    // Spring configuration
    System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, securityImplementation);

    AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext();
    webApplicationContext.register(SecurityConfiguration.class);
    webApplicationContext.setEnvironment((ConfigurableEnvironment) applicationContext.getEnvironment());
    webApplicationContext.setParent(applicationContext);

    context.addEventListener(new ContextLoaderListener(webApplicationContext));

    // Spring Security filter
    context.addFilter(new FilterHolder(new DelegatingFilterProxy("springSecurityFilterChain")), "/*",
            EnumSet.allOf(DispatcherType.class));

    // start the server
    server.start();
}

From source file:net.community.chest.gitcloud.facade.AbstractContextInitializer.java

protected Collection<String> resolveActiveProfiles(ExtendedPlaceholderResolver sourcesResolver) {
    String activeValues = sourcesResolver.resolvePlaceholder(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME);
    if (!StringUtils.isEmpty(activeValues)) {
        logger.info("resolveActiveProfiles(" + AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME + "): "
                + activeValues);/*w  w w . ja va 2  s . co m*/
        return Collections.emptyList();
    }

    activeValues = sourcesResolver.resolvePlaceholder(AbstractEnvironment.DEFAULT_PROFILES_PROPERTY_NAME);
    if (!StringUtils.isEmpty(activeValues)) {
        logger.info("resolveActiveProfiles(" + AbstractEnvironment.DEFAULT_PROFILES_PROPERTY_NAME + "): "
                + activeValues);
        return Collections.emptyList();
    }

    return resolveActiveApplicationProfiles(sourcesResolver);
}

From source file:org.cloudfoundry.identity.uaa.test.TestProfileEnvironment.java

private TestProfileEnvironment() {

    List<Resource> resources = new ArrayList<Resource>();

    for (String location : DEFAULT_PROFILE_CONFIG_FILE_LOCATIONS) {
        location = environment.resolvePlaceholders(location);
        Resource resource = recourceLoader.getResource(location);
        if (resource != null && resource.exists()) {
            resources.add(resource);/*from  w  ww. ja v  a 2s .  c  o  m*/
        }
    }

    YamlMapFactoryBean factory = new YamlMapFactoryBean();
    factory.setResources(resources.toArray(new Resource[resources.size()]));
    factory.setResolutionMethod(ResolutionMethod.OVERRIDE_AND_IGNORE);
    Map<String, Object> properties = factory.getObject();

    logger.debug("Decoding environment properties: " + properties.size());
    if (!properties.isEmpty()) {
        for (String name : properties.keySet()) {
            Object value = properties.get(name);
            if (value instanceof String) {
                properties.put(name, environment.resolvePlaceholders((String) value));
            }
        }
        if (properties.containsKey("spring_profiles")) {
            properties.put(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME,
                    properties.get("spring_profiles"));
        }
        // System properties should override the ones in the config file, so
        // add it last
        environment.getPropertySources().addLast(new NestedMapPropertySource("uaa.yml", properties));
    }

    EnvironmentMapFactoryBean environmentProperties = new EnvironmentMapFactoryBean();
    environmentProperties.setEnvironment(environment);
    environmentProperties.setDefaultProperties(properties);
    Map<String, ?> debugProperties = environmentProperties.getObject();
    logger.debug("Environment properties: " + debugProperties);
}