本文整理了Java中org.springframework.context.annotation.AnnotationConfigApplicationContext.register()
方法的一些代码示例,展示了AnnotationConfigApplicationContext.register()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AnnotationConfigApplicationContext.register()
方法的具体详情如下:
包路径:org.springframework.context.annotation.AnnotationConfigApplicationContext
类名称:AnnotationConfigApplicationContext
方法名:register
[英]Register one or more annotated classes to be processed.
Note that #refresh() must be called in order for the context to fully process the new classes.
[中]注册一个或多个要处理的注释类。
请注意,必须调用#refresh(),以便上下文完全处理新类。
代码示例来源:origin: spring-projects/spring-framework
@Override
protected ApplicationContext initApplicationContext() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(WebConfig.class);
context.refresh();
return context;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected ApplicationContext initApplicationContext() {
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
wac.register(WebConfig.class);
wac.refresh();
return wac;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected ApplicationContext initApplicationContext() {
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
wac.register(WebConfig.class, TestRestController.class);
wac.refresh();
return wac;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Fails with classpath errors on trying to classload AnnotationAsyncExecutionAspect
*/
@Test(expected = BeanDefinitionStoreException.class)
public void aspectModeAspectJAttemptsToRegisterAsyncAspect() {
@SuppressWarnings("resource")
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(AspectJAsyncAnnotationConfig.class);
ctx.refresh();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void autowiringFailsWithBFPPAsInstanceMethod() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(TestBeanConfig.class, AutowiredConfigWithBFPPAsInstanceMethod.class);
ctx.refresh();
// instance method BFPP interferes with lifecycle -> autowiring fails!
// WARN-level logging should have been issued about returning BFPP from non-static @Bean method
assertThat(ctx.getBean(AutowiredConfigWithBFPPAsInstanceMethod.class).autowiredTestBean, nullValue());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void withResolvablePlaceholder() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigWithResolvablePlaceholder.class);
System.setProperty("path.to.properties", "org/springframework/context/annotation");
ctx.refresh();
assertThat(ctx.getBean(TestBean.class).getName(), equalTo("p1TestBean"));
System.clearProperty("path.to.properties");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void getBeansWithAnnotation() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(Config.class, NameConfig.class, UntypedFactoryBean.class);
context.refresh();
context.getBean("testBean");
context.getBean("name");
Map<String, Object> beans = context.getBeansWithAnnotation(Configuration.class);
assertEquals(2, beans.size());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void withCustomFactoryAsMeta() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigWithImplicitName.class, WithCustomFactoryAsMeta.class);
ctx.refresh();
assertThat(ctx.getBean(TestBean.class).getName(), equalTo("P2TESTBEAN"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void withUnresolvablePlaceholderAndDefault() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigWithUnresolvablePlaceholderAndDefault.class);
ctx.refresh();
assertThat(ctx.getBean(TestBean.class).getName(), equalTo("p1TestBean"));
}
代码示例来源:origin: spring-projects/spring-framework
@Before
public void setup() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(TestConfig.class);
ctx.refresh();
this.dispatcherHandler = new DispatcherHandler(ctx);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void repositoryIsTxProxy_withCustomTxManagerName() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.class, CustomTxManagerNameConfig.class);
ctx.refresh();
assertTxProxying(ctx);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void nonAnnotatedService_PTC_true() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(PTCTrue.class, AnnotatedServiceImpl.class);
ctx.refresh();
NonAnnotatedService s = ctx.getBean(NonAnnotatedService.class);
assertTrue("expected a subclass proxy", AopUtils.isCglibProxy(s));
assertThat(s, instanceOf(AnnotatedServiceImpl.class));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
@SuppressWarnings("resource")
public void withConfigurationClassWithPlainFactoryBean() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(ConfigWithPlainFactoryBean.class);
context.refresh();
MyBean myBean = context.getBean("myBean", MyBean.class);
assertSame(context.getBean("myService"), myBean.myService);
myBean.myService.handle();
myBean.myService.handleAsync();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void withScopedProxyThroughAspectJPattern() throws IOException, ClassNotFoundException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ComponentScanWithScopedProxyThroughAspectJPattern.class);
ctx.getBeanFactory().registerScope("myScope", new SimpleMapScope());
ctx.refresh();
// should cast to the interface
FooService bean = (FooService) ctx.getBean("scopedProxyTestBean");
// should be dynamic proxy
assertThat(AopUtils.isJdkDynamicProxy(bean), is(true));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void staticBeanMethodsDoNotRespectScoping() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigWithStaticBeanMethod.class);
ctx.refresh();
assertThat(ConfigWithStaticBeanMethod.testBean(), not(sameInstance(ConfigWithStaticBeanMethod.testBean())));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void mostSpecificDerivedClassDrivesEnvironment_withDevEnvAndDerivedDevConfigClass() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.setEnvironment(devEnv);
ctx.register(DerivedDevConfig.class);
ctx.refresh();
assertThat("should not have dev bean", ctx.containsBean(DEV_BEAN_NAME), is(false));
assertThat("should not have derived dev bean", ctx.containsBean(DERIVED_DEV_BEAN_NAME), is(false));
assertThat("should not have transitive bean", ctx.containsBean(TRANSITIVE_BEAN_NAME), is(false));
}
代码示例来源:origin: spring-projects/spring-framework
private GroovyMarkupView createViewWithUrl(String viewUrl) throws Exception {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(GroovyMarkupConfiguration.class);
ctx.refresh();
GroovyMarkupView view = new GroovyMarkupView();
view.setUrl(viewUrl);
view.setApplicationContext(ctx);
view.afterPropertiesSet();
return view;
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void annotationConfigApplicationContext_withDevEnvAndDevConfigClass() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
assertHasStandardEnvironment(ctx);
ctx.setEnvironment(devEnv);
ctx.register(DevConfig.class);
ctx.refresh();
assertThat("should have dev bean", ctx.containsBean(DEV_BEAN_NAME), is(true));
assertThat("should have transitive bean", ctx.containsBean(TRANSITIVE_BEAN_NAME), is(true));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void annotationConfigApplicationContext_withImportedConfigClasses() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
assertHasStandardEnvironment(ctx);
ctx.setEnvironment(prodEnv);
ctx.register(Config.class);
ctx.refresh();
assertEnvironmentAwareInvoked(ctx, prodEnv);
assertThat("should have prod bean", ctx.containsBean(PROD_BEAN_NAME), is(true));
assertThat("should not have dev bean", ctx.containsBean(DEV_BEAN_NAME), is(false));
assertThat("should not have transitive bean", ctx.containsBean(TRANSITIVE_BEAN_NAME), is(false));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void beanMethodOverriding() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(OverridingConfig.class);
ctx.setAllowBeanDefinitionOverriding(false);
ctx.refresh();
assertFalse(ctx.getDefaultListableBeanFactory().containsSingleton("testBean"));
assertEquals("overridden", ctx.getBean("testBean", TestBean.class).toString());
assertTrue(ctx.getDefaultListableBeanFactory().containsSingleton("testBean"));
}
内容来源于网络,如有侵权,请联系作者删除!