本文整理了Java中org.springframework.context.annotation.AnnotatedBeanDefinitionReader.<init>()
方法的一些代码示例,展示了AnnotatedBeanDefinitionReader.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AnnotatedBeanDefinitionReader.<init>()
方法的具体详情如下:
包路径:org.springframework.context.annotation.AnnotatedBeanDefinitionReader
类名称:AnnotatedBeanDefinitionReader
方法名:<init>
[英]Create a new AnnotatedBeanDefinitionReader for the given registry. If the registry is EnvironmentCapable, e.g. is an ApplicationContext, the Environment will be inherited, otherwise a new StandardEnvironment will be created and used.
[中]为给定注册表创建新的AnnotatedBeanDefinitionReader。如果注册表支持环境,例如是ApplicationContext,则将继承该环境,否则将创建并使用新的StandardEnvironment。
代码示例来源:origin: spring-projects/spring-framework
/**
* Create a new AnnotationConfigApplicationContext that needs to be populated
* through {@link #register} calls and then manually {@linkplain #refresh refreshed}.
*/
public AnnotationConfigApplicationContext() {
this.reader = new AnnotatedBeanDefinitionReader(this);
this.scanner = new ClassPathBeanDefinitionScanner(this);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Create a new AnnotationConfigApplicationContext with the given DefaultListableBeanFactory.
* @param beanFactory the DefaultListableBeanFactory instance to use for this context
*/
public AnnotationConfigApplicationContext(DefaultListableBeanFactory beanFactory) {
super(beanFactory);
this.reader = new AnnotatedBeanDefinitionReader(this);
this.scanner = new ClassPathBeanDefinitionScanner(this);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Build an {@link AnnotatedBeanDefinitionReader} for the given bean factory.
* <p>This should be pre-configured with the {@code Environment} (if desired)
* but not with a {@code BeanNameGenerator} or {@code ScopeMetadataResolver} yet.
* @param beanFactory the bean factory to load bean definitions into
* @since 4.1.9
* @see #getEnvironment()
* @see #getBeanNameGenerator()
* @see #getScopeMetadataResolver()
*/
protected AnnotatedBeanDefinitionReader getAnnotatedBeanDefinitionReader(DefaultListableBeanFactory beanFactory) {
return new AnnotatedBeanDefinitionReader(beanFactory, getEnvironment());
}
代码示例来源:origin: apache/incubator-dubbo
/**
* Register Beans
*
* @param registry {@link BeanDefinitionRegistry}
* @param annotatedClasses {@link Annotation annotation} class
*/
public static void registerBeans(BeanDefinitionRegistry registry, Class<?>... annotatedClasses) {
if (ObjectUtils.isEmpty(annotatedClasses)) {
return;
}
boolean debugEnabled = logger.isDebugEnabled();
AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(registry);
if (debugEnabled) {
logger.debug(registry.getClass().getSimpleName() + " will register annotated classes : " + Arrays.asList(annotatedClasses) + " .");
}
reader.register(annotatedClasses);
}
}
代码示例来源:origin: apache/incubator-dubbo
/**
* Register Beans
*
* @param registry {@link BeanDefinitionRegistry}
* @param annotatedClasses {@link Annotation annotation} class
*/
public static void registerBeans(BeanDefinitionRegistry registry, Class<?>... annotatedClasses) {
if (ObjectUtils.isEmpty(annotatedClasses)) {
return;
}
boolean debugEnabled = logger.isDebugEnabled();
AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(registry);
if (debugEnabled) {
logger.debug(registry.getClass().getSimpleName() + " will register annotated classes : " + Arrays.asList(annotatedClasses) + " .");
}
reader.register(annotatedClasses);
}
}
代码示例来源:origin: org.springframework/spring-context
/**
* Create a new AnnotationConfigApplicationContext that needs to be populated
* through {@link #register} calls and then manually {@linkplain #refresh refreshed}.
*/
public AnnotationConfigApplicationContext() {
this.reader = new AnnotatedBeanDefinitionReader(this);
this.scanner = new ClassPathBeanDefinitionScanner(this);
}
代码示例来源:origin: org.springframework/spring-context
/**
* Create a new AnnotationConfigApplicationContext with the given DefaultListableBeanFactory.
* @param beanFactory the DefaultListableBeanFactory instance to use for this context
*/
public AnnotationConfigApplicationContext(DefaultListableBeanFactory beanFactory) {
super(beanFactory);
this.reader = new AnnotatedBeanDefinitionReader(this);
this.scanner = new ClassPathBeanDefinitionScanner(this);
}
代码示例来源:origin: org.springframework/spring-web
/**
* Build an {@link AnnotatedBeanDefinitionReader} for the given bean factory.
* <p>This should be pre-configured with the {@code Environment} (if desired)
* but not with a {@code BeanNameGenerator} or {@code ScopeMetadataResolver} yet.
* @param beanFactory the bean factory to load bean definitions into
* @since 4.1.9
* @see #getEnvironment()
* @see #getBeanNameGenerator()
* @see #getScopeMetadataResolver()
*/
protected AnnotatedBeanDefinitionReader getAnnotatedBeanDefinitionReader(DefaultListableBeanFactory beanFactory) {
return new AnnotatedBeanDefinitionReader(beanFactory, getEnvironment());
}
代码示例来源:origin: org.springframework.boot/spring-boot
/**
* Create a new {@link AnnotationConfigReactiveWebServerApplicationContext} with the
* given {@code DefaultListableBeanFactory}. The context needs to be populated through
* {@link #register} calls and then manually {@linkplain #refresh refreshed}.
* @param beanFactory the DefaultListableBeanFactory instance to use for this context
*/
public AnnotationConfigReactiveWebServerApplicationContext(
DefaultListableBeanFactory beanFactory) {
super(beanFactory);
this.reader = new AnnotatedBeanDefinitionReader(this);
this.scanner = new ClassPathBeanDefinitionScanner(this);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Register classes in the supplied {@linkplain GenericWebApplicationContext context}
* from the classes in the supplied {@link WebMergedContextConfiguration}.
* <p>Each class must represent an <em>annotated class</em>. An
* {@link AnnotatedBeanDefinitionReader} is used to register the appropriate
* bean definitions.
* @param context the context in which the annotated classes should be registered
* @param webMergedConfig the merged configuration from which the classes should be retrieved
* @see AbstractGenericWebContextLoader#loadBeanDefinitions
*/
@Override
protected void loadBeanDefinitions(
GenericWebApplicationContext context, WebMergedContextConfiguration webMergedConfig) {
Class<?>[] annotatedClasses = webMergedConfig.getClasses();
if (logger.isDebugEnabled()) {
logger.debug("Registering annotated classes: " + ObjectUtils.nullSafeToString(annotatedClasses));
}
new AnnotatedBeanDefinitionReader(context).register(annotatedClasses);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Register classes in the supplied {@link GenericApplicationContext context}
* from the classes in the supplied {@link MergedContextConfiguration}.
* <p>Each class must represent an <em>annotated class</em>. An
* {@link AnnotatedBeanDefinitionReader} is used to register the appropriate
* bean definitions.
* <p>Note that this method does not call {@link #createBeanDefinitionReader}
* since {@code AnnotatedBeanDefinitionReader} is not an instance of
* {@link BeanDefinitionReader}.
* @param context the context in which the annotated classes should be registered
* @param mergedConfig the merged configuration from which the classes should be retrieved
* @see AbstractGenericContextLoader#loadBeanDefinitions
*/
@Override
protected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) {
Class<?>[] annotatedClasses = mergedConfig.getClasses();
if (logger.isDebugEnabled()) {
logger.debug("Registering annotated classes: " + ObjectUtils.nullSafeToString(annotatedClasses));
}
new AnnotatedBeanDefinitionReader(context).register(annotatedClasses);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void initialize(GenericApplicationContext applicationContext) {
new AnnotatedBeanDefinitionReader(applicationContext).register(GlobalConfig.class);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void initialize(GenericApplicationContext applicationContext) {
new AnnotatedBeanDefinitionReader(applicationContext).register(FooConfig.class);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void securityManagerDisallowsAccessToSystemEnvironmentButAllowsAccessToIndividualKeys() {
SecurityManager securityManager = new SecurityManager() {
@Override
public void checkPermission(Permission perm) {
// Disallowing access to System#getenv means that our
// ReadOnlySystemAttributesMap will come into play.
if ("getenv.*".equals(perm.getName())) {
throw new AccessControlException("Accessing the system environment is disallowed");
}
}
};
System.setSecurityManager(securityManager);
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(bf);
reader.register(C1.class);
assertThat(bf.containsBean("c1"), is(true));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void securityManagerDisallowsAccessToSystemEnvironmentAndDisallowsAccessToIndividualKey() {
SecurityManager securityManager = new SecurityManager() {
@Override
public void checkPermission(Permission perm) {
// Disallowing access to System#getenv means that our
// ReadOnlySystemAttributesMap will come into play.
if ("getenv.*".equals(perm.getName())) {
throw new AccessControlException("Accessing the system environment is disallowed");
}
// Disallowing access to the spring.profiles.active property means that
// the BeanDefinitionReader won't be able to determine which profiles are
// active. We should see an INFO-level message in the console about this
// and as a result, any components marked with a non-default profile will
// be ignored.
if (("getenv." + AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME).equals(perm.getName())) {
throw new AccessControlException(
format("Accessing system environment variable [%s] is disallowed",
AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME));
}
}
};
System.setSecurityManager(securityManager);
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(bf);
reader.register(C1.class);
assertThat(bf.containsBean("c1"), is(false));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void annotatedBeanDefinitionReader_inheritsEnvironmentFromEnvironmentCapableBDR() {
GenericApplicationContext ctx = new GenericApplicationContext();
ctx.setEnvironment(prodEnv);
new AnnotatedBeanDefinitionReader(ctx).register(Config.class);
ctx.refresh();
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) {
// Order doesn't matter: <bean> always wins over @Bean.
new XmlBeanDefinitionReader(context).loadBeanDefinitions(mergedConfig.getLocations());
new AnnotatedBeanDefinitionReader(context).register(mergedConfig.getClasses());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void cronTaskWithScopedProxy() {
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
context.registerBeanDefinition("postProcessor", processorDefinition);
new AnnotatedBeanDefinitionReader(context).register(ProxiedCronTestBean.class, ProxiedCronTestBeanDependent.class);
context.refresh();
ScheduledTaskHolder postProcessor = context.getBean("postProcessor", ScheduledTaskHolder.class);
assertEquals(1, postProcessor.getScheduledTasks().size());
ScheduledTaskRegistrar registrar = (ScheduledTaskRegistrar)
new DirectFieldAccessor(postProcessor).getPropertyValue("registrar");
@SuppressWarnings("unchecked")
List<CronTask> cronTasks = (List<CronTask>)
new DirectFieldAccessor(registrar).getPropertyValue("cronTasks");
assertEquals(1, cronTasks.size());
CronTask task = cronTasks.get(0);
ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) task.getRunnable();
Object targetObject = runnable.getTarget();
Method targetMethod = runnable.getMethod();
assertEquals(context.getBean(ScopedProxyUtils.getTargetBeanName("target")), targetObject);
assertEquals("cron", targetMethod.getName());
assertEquals("*/7 * * * * ?", task.getExpression());
}
代码示例来源:origin: spring-projects/spring-framework
public static Test suite() {
GenericApplicationContext ac = new GenericApplicationContext();
AnnotatedBeanDefinitionReader bdr = new AnnotatedBeanDefinitionReader(ac);
bdr.setScopeMetadataResolver(new Jsr330ScopeMetadataResolver());
bdr.registerBean(Convertible.class);
bdr.registerBean(DriversSeat.class, Drivers.class);
bdr.registerBean(Seat.class, Primary.class);
bdr.registerBean(V8Engine.class);
bdr.registerBean(SpareTire.class, "spare");
bdr.registerBean(Cupholder.class);
bdr.registerBean(Tire.class, Primary.class);
bdr.registerBean(FuelTank.class);
ac.refresh();
Car car = ac.getBean(Car.class);
return Tck.testsFor(car, false, true);
}
代码示例来源:origin: spring-projects/spring-framework
@Before
public void setUp() {
ServletContext servletContext = new MockServletContext();
MockHttpServletRequest mockRequest = new MockHttpServletRequest(servletContext);
mockRequest.setAttribute(FROM_CUSTOM_MOCK, FROM_CUSTOM_MOCK);
RequestContextHolder.setRequestAttributes(new ServletWebRequest(mockRequest, new MockHttpServletResponse()));
this.wac.setServletContext(servletContext);
new AnnotatedBeanDefinitionReader(this.wac).register(WebConfig.class);
this.wac.refresh();
this.mockMvc = webAppContextSetup(this.wac)
.defaultRequest(get("/").requestAttr(FROM_MVC_TEST_DEFAULT, FROM_MVC_TEST_DEFAULT))
.alwaysExpect(status().isOk())
.build();
}
内容来源于网络,如有侵权,请联系作者删除!