Spring Framework AnnotationConfigApplicationContext - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework AnnotationConfigApplicationContext class.

This code example shows how to use the following methods:register, getBean, getBean, refresh
 
    @Test
    public void processEngineWithJpaEntityManager() throws Exception {
        AnnotationConfigApplicationContext context = this.context(DataSourceAutoConfiguration.class,
                HibernateJpaAutoConfiguration.class, JpaProcessEngineAutoConfiguration.JpaConfiguration.class); 
        Assert.assertNotNull("entityManagerFactory should not be null", context.getBean(EntityManagerFactory.class));
        Assert.assertNotNull("the processEngine should not be null!", context.getBean(ProcessEngine.class));
        SpringProcessEngineConfiguration configuration = context.getBean(SpringProcessEngineConfiguration.class);
        Assert.assertNotNull("the " + SpringProcessEngineConfiguration.class.getName() + " should not be null", configuration);
        Assert.assertNotNull(configuration.getJpaEntityManagerFactory());
    } 
 
    @Test
    public void processEngineWithBasicDataSource() throws Exception {
        AnnotationConfigApplicationContext context = this.context(
                DataSourceAutoConfiguration.class, DataSourceProcessEngineAutoConfiguration.DataSourceConfiguration.class); 
        Assert.assertNotNull("the processEngine should not be null!", context.getBean(ProcessEngine.class));
    } 
 
    @Test

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:scan, refresh
 */ 
public class Spr8955Tests { 
 
	@Test
	public void repro() { 
		AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
		ctx.scan("org.springframework.context.annotation.configuration.spr8955");
		ctx.refresh();
	} 
 
} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:register, refresh
package test; 
 
import org.junit.Test; 
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
 
public class ContextTest { 
 
	@Test
	public void repro() { 
		AnnotationConfigApplicationContext ctx =
				new AnnotationConfigApplicationContext();
		ctx.register(FirstDao.class);
		ctx.register(SecondDao.class);
		ctx.register(FirstService.class);
		ctx.register(SecondService.class);
		ctx.refresh();
	} 
 
} 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:register, getBean, refresh, registerShutdownHook
 
	private PollableChannel tweets;
 
	@Before 
	public void setup() { 
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
		context.register(SearchReceivingMessageSourceWithRedisTestsConfig.class);
		context.registerShutdownHook();
		context.refresh();
 
		this.twitterSearchAdapter = context.getBean(SourcePollingChannelAdapter.class);
		this.twitterMessageSource = context.getBean(AbstractTwitterMessageSource.class);
		this.metadataStore = context.getBean(MetadataStore.class);
		this.tweets = context.getBean("inbound_twitter", PollableChannel.class);
 
		this.metadataKey = TestUtils.getPropertyValue(twitterSearchAdapter, "source.metadataKey", String.class);
 
		// There is need to set a value, not 'remove' and re-init 'twitterMessageSource' 
		this.metadataStore.put(metadataKey, "-1");
 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:register, refresh
		return response; 
	} 
 
	private GroovyMarkupView createViewWithUrl(String viewUrl) throws Exception { 
 
		AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); 
		ctx.register(GroovyMarkupConfiguration.class); 
		ctx.refresh(); 
 
		GroovyMarkupView view = new GroovyMarkupView(); 
		view.setApplicationContext(ctx); 
		view.setUrl(viewUrl); 
		view.afterPropertiesSet(); 
		return view; 
	} 
 
	public class TestTemplateEngine extends MarkupTemplateEngine { 
 
		public TestTemplateEngine() { 
			super(new TemplateConfiguration()); 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:close, getBean
	private static final String NATS_BEAN = "natsBean";
	private static final String WRONG_NATS_BEAN = "wrongNatsBean";
 
	@Test
	public void subscribeAnnotationNamedNatsBean() { 
		final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(NamedNatsAnnotationConfig.class);
		try { 
			final Nats nats = context.getBean(NATS_BEAN, Nats.class);
			final Nats wrongNats = context.getBean(WRONG_NATS_BEAN, Nats.class);
			wrongNats.publish("test", "Should not get processed");
			testNatsConfig(context, nats);
		} finally { 
			context.close();
		} 
	} 
 
	private void testNatsConfig(AnnotationConfigApplicationContext context, Nats nats) {
		assertNotNull(nats);
 
		final String body = "Java config is cool.";
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:scan, getBean, getEnvironment, refresh
    private static boolean usePdx;
	public static void main(String args[]) {
		 
		usePdx = args.length > 0 && args[0].toUpperCase().contains("PDX");  
		 
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
		if (usePdx) {
			log.info("PDX is enabled");
			File pdxDir = new File("pdx");
			if (!pdxDir.exists()){
				new File("pdx").mkdir();
			} 
			context.getEnvironment().setActiveProfiles("pdx");
		} 
	  
		context.scan("org.springframework.data.gemfire.examples");
		context.refresh();
		 
		 OrderExample orderExample = context.getBean(OrderExample.class);
		 orderExample.run();

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:scan, refresh
     * @return the created instance of {@link AnnotationConfigApplicationContext} 
     */ 
    private ApplicationContext createAnnotatedApplicationContext(Class<?>[] classes, String[] packages) {
 
        if (classes.length > 0) {
            AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(classes);
 
            if (packages.length > 0) {
                applicationContext.scan(packages);
                applicationContext.refresh();
            } 
 
            return applicationContext;
 
        } else { 
 
            return new AnnotationConfigApplicationContext(packages);
        } 
    } 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:register, refresh, setParent
     * @param args 
     */ 
    public static void main(String[] args) {
 
        ApplicationContext parent = new AnnotationConfigApplicationContext(ParentApplicationContextConfiguration.class);
        AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext();
        child.register(ChildApplicationContextConfiguration.class);
        child.setParent(parent);
        child.refresh();
 
        transfer(child);
 
        ApplicationContextLogger.log(child);
        ApplicationContextLogger.log(parent);
    } 
 
    private static void transfer(ApplicationContext ctx) {
        MoneyTransferService service = ctx.getBean("moneyTransferService", MoneyTransferService.class);
        Transaction transaction = service.transfer("123456", "654321", new BigDecimal("250.00"));
 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
public class SpringDefaultProfileResourceTest extends JerseyTest { 
 
    @Override 
    protected Application configure() {
        System.setProperty("spring.profiles.active", "");
        ApplicationContext context = new AnnotationConfigApplicationContext("org.glassfish.jersey.server.spring.profiles");
        return new ResourceConfig() 
                .register(RequestContextFilter.class) 
                .register(LoggingFilter.class) 
                .packages("org.glassfish.jersey.server.spring.profiles") 
                .property("contextConfig", context);
    } 
 
    @Test
    public void shouldUseDefaultComponent() { 
        final String result = target("spring-resource").request().get(String.class);
        Assert.assertEquals("default", result);
    } 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Spring Framework AnnotationConfigApplicationContext Methods: