當前位置: 首頁>>代碼示例>>Java>>正文


Java ConfigurableEnvironment.setActiveProfiles方法代碼示例

本文整理匯總了Java中org.springframework.core.env.ConfigurableEnvironment.setActiveProfiles方法的典型用法代碼示例。如果您正苦於以下問題:Java ConfigurableEnvironment.setActiveProfiles方法的具體用法?Java ConfigurableEnvironment.setActiveProfiles怎麽用?Java ConfigurableEnvironment.setActiveProfiles使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.core.env.ConfigurableEnvironment的用法示例。


在下文中一共展示了ConfigurableEnvironment.setActiveProfiles方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
public static void main(String[] args) {
//        ApplicationContext context = new AnnotationConfigApplicationContext("com");
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.register(Config.class);
//        context.getEnvironment().addActiveProfile("dev");
        ConfigurableEnvironment environment = context.getEnvironment();
        environment.setDefaultProfiles("dev");
        environment.setActiveProfiles("prod");
        context.refresh();

        Student student = (Student) context.getBean("student");
        Student SpELStudent = (Student) context.getBean("SpELStudent");
        Teacher teacher = (Teacher) context.getBean("teacher");
        System.out.println(student);
        System.out.println(SpELStudent);
        System.out.println(teacher);
        System.out.println(teacher.getPen());

        teacher.teach("Math");
        System.out.println(teacher.getPenColor());
    }
 
開發者ID:Ulyssesss,項目名稱:java-demo,代碼行數:22,代碼來源:Test.java

示例2: getBean_withActiveProfile

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
@Test
public void getBean_withActiveProfile() {
	ConfigurableEnvironment env = new StandardEnvironment();
	env.setActiveProfiles("dev");

	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
	reader.setEnvironment(env);
	reader.loadBeanDefinitions(XML);

	bf.getBean("devOnlyBean"); // should not throw NSBDE

	Object foo = bf.getBean("foo");
	assertThat(foo, instanceOf(Integer.class));

	bf.getBean("devOnlyBean");
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:NestedBeansElementTests.java

示例3: initialize

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
@Override
public void initialize( XmlWebApplicationContext applicationContext )
{
  ConfigurableEnvironment env = applicationContext.getEnvironment();

  WorkDir workDir;
  try
  {
    workDir = new WorkDir( applicationContext.getServletContext() );
  }
  catch ( IOException e )
  {
    throw new ApplicationContextException( "Error obtaining QuartzDesk Executor work directory.", e );
  }

  String databaseProfile = getDatabaseProfile( workDir );

  String[] activeProfiles = new String[] { databaseProfile };

  log.info( "Activating Spring profiles: {}", Arrays.toString( activeProfiles ) );

  env.setActiveProfiles( activeProfiles );
}
 
開發者ID:quartzdesk,項目名稱:quartzdesk-executor,代碼行數:24,代碼來源:SpringProfilesActivator.java

示例4: testWithInactiveProfile

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
@Test
public void testWithInactiveProfile() {
	ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
	ConfigurableEnvironment env = new StandardEnvironment();
	env.setActiveProfiles("other");
	provider.setEnvironment(env);
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_PROFILE_PACKAGE);
	assertThat(containsBeanClass(candidates, ProfileAnnotatedComponent.class), is(false));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:10,代碼來源:ClassPathScanningCandidateComponentProviderTests.java

示例5: testWithActiveProfile

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
@Test
public void testWithActiveProfile() {
	ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
	ConfigurableEnvironment env = new StandardEnvironment();
	env.setActiveProfiles(ProfileAnnotatedComponent.PROFILE_NAME);
	provider.setEnvironment(env);
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_PROFILE_PACKAGE);
	assertThat(containsBeanClass(candidates, ProfileAnnotatedComponent.class), is(true));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:10,代碼來源:ClassPathScanningCandidateComponentProviderTests.java

示例6: handleRequest

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
@Override
protected void handleRequest(AwsProxyHttpServletRequest containerRequest, AwsHttpServletResponse containerResponse, Context lambdaContext) throws Exception {
    // this method of the AwsLambdaServletContainerHandler sets the servlet context
    if (getServletContext() == null) {
        setServletContext(new SpringBootAwsServletContext());
    }

    // wire up the application context on the first invocation
    if (!initialized) {
        if (springProfiles != null && springProfiles.length > 0) {
            System.setProperty("spring.profiles.active", String.join(",", springProfiles));
        }
        SpringServletContainerInitializer springServletContainerInitializer = new SpringServletContainerInitializer();
        LinkedHashSet<Class<?>> webAppInitializers = new LinkedHashSet<>();
        webAppInitializers.add(springBootInitializer);
        springServletContainerInitializer.onStartup(webAppInitializers, getServletContext());

        if (springProfiles != null && springProfiles.length > 0) {
            ConfigurableEnvironment springEnv = new StandardEnvironment();
            springEnv.setActiveProfiles(springProfiles);
            
        }

        initialized = true;
    }

    containerRequest.setServletContext(getServletContext());

    WebApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());

    DispatcherServlet dispatcherServlet = applicationContext.getBean("dispatcherServlet", DispatcherServlet.class);
    // process filters & invoke servlet
    doFilter(containerRequest, containerResponse, dispatcherServlet);
}
 
開發者ID:awslabs,項目名稱:aws-serverless-java-container,代碼行數:35,代碼來源:SpringBootLambdaContainerHandler.java

示例7: prependProfile

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
private void prependProfile(ConfigurableEnvironment environment,
		Profile profile) {
	Set<String> profiles = new LinkedHashSet<String>();
	environment.getActiveProfiles(); // ensure they are initialized
	// But this one should go first (last wins in a property key clash)
	profiles.add(profile.getName());
	profiles.addAll(Arrays.asList(environment.getActiveProfiles()));
	environment.setActiveProfiles(profiles.toArray(new String[profiles.size()]));
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:10,代碼來源:ConfigFileApplicationListener.java

示例8: prependProfile

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
private void prependProfile(ConfigurableEnvironment environment, String profile) {
	Set<String> profiles = new LinkedHashSet<String>();
	environment.getActiveProfiles(); // ensure they are initialized
	// But this one should go first (last wins in a property key clash)
	profiles.add(profile);
	profiles.addAll(Arrays.asList(environment.getActiveProfiles()));
	environment.setActiveProfiles(profiles.toArray(new String[profiles.size()]));
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:9,代碼來源:ConfigFileApplicationListener.java

示例9: setConfigurationAsTypeSpringApplicationContext

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
protected void setConfigurationAsTypeSpringApplicationContext(GenericXmlApplicationContext ctx, ConfigureProfile profile, String[] placeContext) {
    ConfigurableEnvironment env = ctx.getEnvironment(); 
    env.setActiveProfiles(profile.value()); 
    ctx.load(placeContext); 
    ctx.refresh(); 
}
 
開發者ID:linux-china,項目名稱:unitils,代碼行數:7,代碼來源:ProfileModule.java

示例10: configureProfiles

import org.springframework.core.env.ConfigurableEnvironment; //導入方法依賴的package包/類
/**
 * Configure which profiles are active (or active by default) for this application
 * environment. Additional profiles may be activated during configuration file
 * processing via the {@code spring.profiles.active} property.
 * @param environment this application's environment
 * @param args arguments passed to the {@code run} method
 * @see #configureEnvironment(ConfigurableEnvironment, String[])
 * @see org.springframework.boot.context.config.ConfigFileApplicationListener
 */
protected void configureProfiles(ConfigurableEnvironment environment, String[] args) {
	environment.getActiveProfiles(); // ensure they are initialized
	// But these ones should go first (last wins in a property key clash)
	Set<String> profiles = new LinkedHashSet<String>(this.additionalProfiles);
	profiles.addAll(Arrays.asList(environment.getActiveProfiles()));
	environment.setActiveProfiles(profiles.toArray(new String[profiles.size()]));
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:17,代碼來源:SpringApplication.java


注:本文中的org.springframework.core.env.ConfigurableEnvironment.setActiveProfiles方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。