Search in sources :

Example 1 with AnnotatedBeanDefinitionReader

use of org.springframework.context.annotation.AnnotatedBeanDefinitionReader in project spring-boot by spring-projects.

the class ImportsContextCustomizer method customizeContext.

@Override
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedContextConfiguration) {
    BeanDefinitionRegistry registry = getBeanDefinitionRegistry(context);
    AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(registry);
    registerCleanupPostProcessor(registry, reader);
    registerImportsConfiguration(registry, reader);
}
Also used : BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) AnnotatedBeanDefinitionReader(org.springframework.context.annotation.AnnotatedBeanDefinitionReader)

Example 2 with AnnotatedBeanDefinitionReader

use of org.springframework.context.annotation.AnnotatedBeanDefinitionReader in project spring-framework by spring-projects.

the class EnvironmentSecurityManagerIntegrationTests method securityManagerDisallowsAccessToSystemEnvironmentAndDisallowsAccessToIndividualKey.

@Test
public void securityManagerDisallowsAccessToSystemEnvironmentAndDisallowsAccessToIndividualKey() {
    SecurityManager securityManager = new SecurityManager() {

        @Override
        public void checkPermission(Permission perm) {
            // ReadOnlySystemAttributesMap will come into play.
            if ("getenv.*".equals(perm.getName())) {
                throw new AccessControlException("Accessing the system environment is disallowed");
            }
            // 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));
}
Also used : Permission(java.security.Permission) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) AccessControlException(java.security.AccessControlException) AnnotatedBeanDefinitionReader(org.springframework.context.annotation.AnnotatedBeanDefinitionReader) Test(org.junit.Test)

Example 3 with AnnotatedBeanDefinitionReader

use of org.springframework.context.annotation.AnnotatedBeanDefinitionReader in project spring-framework by spring-projects.

the class AnnotationConfigContextLoader method loadBeanDefinitions.

/**
	 * 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);
}
Also used : AnnotatedBeanDefinitionReader(org.springframework.context.annotation.AnnotatedBeanDefinitionReader)

Example 4 with AnnotatedBeanDefinitionReader

use of org.springframework.context.annotation.AnnotatedBeanDefinitionReader in project spring-framework by spring-projects.

the class EnvironmentSystemIntegrationTests method annotatedBeanDefinitionReader_inheritsEnvironmentFromEnvironmentCapableBDR.

@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));
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) AnnotatedBeanDefinitionReader(org.springframework.context.annotation.AnnotatedBeanDefinitionReader) Test(org.junit.Test)

Example 5 with AnnotatedBeanDefinitionReader

use of org.springframework.context.annotation.AnnotatedBeanDefinitionReader in project spring-framework by spring-projects.

the class SpringAtInjectTck method suite.

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);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) Car(org.atinject.tck.auto.Car) Jsr330ScopeMetadataResolver(org.springframework.context.annotation.Jsr330ScopeMetadataResolver) AnnotatedBeanDefinitionReader(org.springframework.context.annotation.AnnotatedBeanDefinitionReader)

Aggregations

AnnotatedBeanDefinitionReader (org.springframework.context.annotation.AnnotatedBeanDefinitionReader)10 Test (org.junit.Test)3 AccessControlException (java.security.AccessControlException)2 Permission (java.security.Permission)2 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)2 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)2 ServletContext (javax.servlet.ServletContext)1 Car (org.atinject.tck.auto.Car)1 Before (org.junit.Before)1 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)1 BeanNameGenerator (org.springframework.beans.factory.support.BeanNameGenerator)1 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)1 ClassPathBeanDefinitionScanner (org.springframework.context.annotation.ClassPathBeanDefinitionScanner)1 Jsr330ScopeMetadataResolver (org.springframework.context.annotation.Jsr330ScopeMetadataResolver)1 ScopeMetadataResolver (org.springframework.context.annotation.ScopeMetadataResolver)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 MockServletContext (org.springframework.mock.web.MockServletContext)1 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)1