Java Code Examples for org.springframework.context.support.GenericApplicationContext#registerAlias()

The following examples show how to use org.springframework.context.support.GenericApplicationContext#registerAlias() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PersistenceInjectionTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testPublicPersistenceUnitSetterWithUnitIdentifiedThroughBeanName() {
	EntityManagerFactory mockEmf2 = mock(EntityManagerFactory.class);

	GenericApplicationContext gac = new GenericApplicationContext();
	gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
	gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory2", mockEmf2);
	gac.registerAlias("entityManagerFactory2", "Person");
	RootBeanDefinition processorDef = new RootBeanDefinition(PersistenceAnnotationBeanPostProcessor.class);
	processorDef.getPropertyValues().add("defaultPersistenceUnitName", "entityManagerFactory");
	gac.registerBeanDefinition("annotationProcessor", processorDef);
	gac.registerBeanDefinition(DefaultPublicPersistenceUnitSetter.class.getName(),
			new RootBeanDefinition(DefaultPublicPersistenceUnitSetter.class));
	gac.registerBeanDefinition(DefaultPublicPersistenceUnitSetterNamedPerson.class.getName(),
			new RootBeanDefinition(DefaultPublicPersistenceUnitSetterNamedPerson.class));
	gac.refresh();

	DefaultPublicPersistenceUnitSetter bean = (DefaultPublicPersistenceUnitSetter)
			gac.getBean(DefaultPublicPersistenceUnitSetter.class.getName());
	DefaultPublicPersistenceUnitSetterNamedPerson bean2 = (DefaultPublicPersistenceUnitSetterNamedPerson)
			gac.getBean(DefaultPublicPersistenceUnitSetterNamedPerson.class.getName());
	assertSame(mockEmf, bean.emf);
	assertSame(mockEmf2, bean2.emf);
}
 
Example 2
Source File: PersistenceInjectionTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testPublicPersistenceUnitSetterWithUnitIdentifiedThroughBeanName() {
	EntityManagerFactory mockEmf2 = mock(EntityManagerFactory.class);

	GenericApplicationContext gac = new GenericApplicationContext();
	gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
	gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory2", mockEmf2);
	gac.registerAlias("entityManagerFactory2", "Person");
	RootBeanDefinition processorDef = new RootBeanDefinition(PersistenceAnnotationBeanPostProcessor.class);
	processorDef.getPropertyValues().add("defaultPersistenceUnitName", "entityManagerFactory");
	gac.registerBeanDefinition("annotationProcessor", processorDef);
	gac.registerBeanDefinition(DefaultPublicPersistenceUnitSetter.class.getName(),
			new RootBeanDefinition(DefaultPublicPersistenceUnitSetter.class));
	gac.registerBeanDefinition(DefaultPublicPersistenceUnitSetterNamedPerson.class.getName(),
			new RootBeanDefinition(DefaultPublicPersistenceUnitSetterNamedPerson.class));
	gac.refresh();

	DefaultPublicPersistenceUnitSetter bean = (DefaultPublicPersistenceUnitSetter)
			gac.getBean(DefaultPublicPersistenceUnitSetter.class.getName());
	DefaultPublicPersistenceUnitSetterNamedPerson bean2 = (DefaultPublicPersistenceUnitSetterNamedPerson)
			gac.getBean(DefaultPublicPersistenceUnitSetterNamedPerson.class.getName());
	assertSame(mockEmf, bean.emf);
	assertSame(mockEmf2, bean2.emf);
}
 
Example 3
Source File: PersistenceInjectionTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testPublicPersistenceUnitSetterWithUnitIdentifiedThroughBeanName() {
	EntityManagerFactory mockEmf2 = mock(EntityManagerFactory.class);

	GenericApplicationContext gac = new GenericApplicationContext();
	gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
	gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory2", mockEmf2);
	gac.registerAlias("entityManagerFactory2", "Person");
	RootBeanDefinition processorDef = new RootBeanDefinition(PersistenceAnnotationBeanPostProcessor.class);
	processorDef.getPropertyValues().add("defaultPersistenceUnitName", "entityManagerFactory");
	gac.registerBeanDefinition("annotationProcessor", processorDef);
	gac.registerBeanDefinition(DefaultPublicPersistenceUnitSetter.class.getName(),
			new RootBeanDefinition(DefaultPublicPersistenceUnitSetter.class));
	gac.registerBeanDefinition(DefaultPublicPersistenceUnitSetterNamedPerson.class.getName(),
			new RootBeanDefinition(DefaultPublicPersistenceUnitSetterNamedPerson.class));
	gac.refresh();

	DefaultPublicPersistenceUnitSetter bean = (DefaultPublicPersistenceUnitSetter)
			gac.getBean(DefaultPublicPersistenceUnitSetter.class.getName());
	DefaultPublicPersistenceUnitSetterNamedPerson bean2 = (DefaultPublicPersistenceUnitSetterNamedPerson)
			gac.getBean(DefaultPublicPersistenceUnitSetterNamedPerson.class.getName());
	assertSame(mockEmf, bean.emf);
	assertSame(mockEmf2, bean2.emf);
}
 
Example 4
Source File: FooBarAliasInitializer.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public void initialize(GenericApplicationContext applicationContext) {
	applicationContext.registerAlias("foo", "bar");
}
 
Example 5
Source File: FooBarAliasInitializer.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public void initialize(GenericApplicationContext applicationContext) {
	applicationContext.registerAlias("foo", "bar");
}
 
Example 6
Source File: FooBarAliasInitializer.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(GenericApplicationContext applicationContext) {
	applicationContext.registerAlias("foo", "bar");
}