当前位置: 首页>>代码示例>>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;未经允许,请勿转载。