Example usage for org.springframework.context ApplicationContext getAutowireCapableBeanFactory

List of usage examples for org.springframework.context ApplicationContext getAutowireCapableBeanFactory

Introduction

In this page you can find the example usage for org.springframework.context ApplicationContext getAutowireCapableBeanFactory.

Prototype

AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException;

Source Link

Document

Expose AutowireCapableBeanFactory functionality for this context.

Usage

From source file:sample.MyConfigurer.java

@SuppressWarnings("unchecked")
@Override/*from ww w .j  av  a2 s  .com*/
public void init(HttpSecurity http) throws Exception {
    // autowire this bean
    ApplicationContext context = http.getSharedObject(ApplicationContext.class);
    context.getAutowireCapableBeanFactory().autowireBean(this);

    // Our DSL allows to grant access to URLs defined by permitAllPattern in a property
    // and then requires authentication for any other request
    http.authorizeRequests().antMatchers(permitAllPattern).permitAll().anyRequest().authenticated();

    if (http.getConfigurer(FormLoginConfigurer.class) == null) {
        // only apply if formLogin() was not invoked by the user
        // this is a way of providing a default, but allow users to override
        http.formLogin().loginPage(loginPage);
    }
}

From source file:jrouter.spring.SpringObjectFactory.java

@Override
public final void setApplicationContext(ApplicationContext applicationContext) {
    autowireCapableBeanFactory = applicationContext.getAutowireCapableBeanFactory();
}

From source file:guru.qas.martini.MartiniConfiguration.java

@Override
public void setApplicationContext(@Nonnull ApplicationContext applicationContext) throws BeansException {
    beanFactory = applicationContext.getAutowireCapableBeanFactory();
}

From source file:ar.com.cema.methodology.analyzer.ui.servlet.DependencyInjectionHttpServlet.java

@Override
public final void init() throws ServletException {
    try {//ww w  .java  2  s  . co  m
        ApplicationContext ctx = getApplicationContext();
        AutowireCapableBeanFactory beanFactory = ctx.getAutowireCapableBeanFactory();
        beanFactory.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_NO, false);
        beanFactory.initializeBean(this, getClass().getName());
    } catch (Exception e) {
        throw new ServletException(
                "Error injecting dependencies on servlet '" + getServletName() + "': " + e.getMessage(), e);
    }
    postInit();
}

From source file:io.nuun.plugin.spring.SpringPluginTest.java

@Test
public void canHandle_should_return_true_for_bean_factory_classes() {
    InternalDependencyInjectionProvider provider = new InternalDependencyInjectionProvider();
    ApplicationContext application = new StaticApplicationContext();
    assertThat(provider.canHandle(application.getAutowireCapableBeanFactory().getClass())).isTrue();
}

From source file:org.usergrid.benchmark.commands.ToolBase.java

public void startSpring() {

    // copy("/testApplicationContext.xml", TMP);

    String[] locations = { "benchmark-context.xml" };
    ApplicationContext ac = new ClassPathXmlApplicationContext(locations);

    AutowireCapableBeanFactory acbf = ac.getAutowireCapableBeanFactory();
    acbf.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_NO, false);
    acbf.initializeBean(this, "tool");

}

From source file:org.snaker.engine.spring.SpringContext.java

/**
 * ?springSpringContext//from w w  w . j  a v  a  2  s. c  om
 * @param ctx 
 */
public SpringContext(ApplicationContext ctx) {
    this.applicationContext = ctx;
    beanFactory = (DefaultListableBeanFactory) ctx.getAutowireCapableBeanFactory();
}

From source file:com.zenika.stripes.contrib.spring.SpringNameBasedActionResolver.java

/**
 * Helper method to construct and return a new ActionBean instance. Called whenever a new
 * instance needs to be manufactured. Provides a convenient point for subclasses to add
 * specific behaviour during action bean creation.
 * //from  w ww . j  a v a  2  s. co m
 * ActionBean are instancied from the Spring factory AutowireCapableBeanFactory.
 * @see <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.springframework/spring-beans/3.0.2.RELEASE/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java#AbstractAutowireCapableBeanFactory.createBean%28java.lang.Class%29">createBean code</a>
 *
 * @param type the type of ActionBean to create
 * @param context the current ActionBeanContext
 * @return the new ActionBean instance
 * @throws Exception if anything goes wrong!
 */
@Override
protected ActionBean makeNewActionBean(Class<? extends ActionBean> type, ActionBeanContext context) {
    ServletContext servletContext = StripesFilter.getConfiguration().getServletContext();
    ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);

    AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
    ActionBean actionBean = (ActionBean) beanFactory.createBean(type, AutowireCapableBeanFactory.AUTOWIRE_NO,
            false);

    return actionBean;
}

From source file:org.usergrid.mongo.MongoServer.java

public void startSpring() {

    String[] locations = getApplicationContextLocations();
    ApplicationContext ac = new ClassPathXmlApplicationContext(locations);

    AutowireCapableBeanFactory acbf = ac.getAutowireCapableBeanFactory();
    acbf.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
    acbf.initializeBean(this, "mongoServer");

    assertNotNull(emf);/*from w  w  w.  ja  v  a 2  s .c om*/
    assertTrue("EntityManagerFactory is instance of EntityManagerFactoryImpl",
            emf instanceof EntityManagerFactoryImpl);

}

From source file:guru.qas.martini.annotation.StepsAnnotationProcessor.java

@Override
public void setApplicationContext(@Nonnull ApplicationContext context) throws BeansException {
    this.context = context;
    AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory();
    checkState(ConfigurableListableBeanFactory.class.isInstance(beanFactory),
            "Martini requires the use of a ConfigurableListableBeanFactory");
    ConfigurableListableBeanFactory configurable = ConfigurableListableBeanFactory.class.cast(beanFactory);
    callbacks = ImmutableList.<ReflectionUtils.MethodCallback>builder()
            .add(new MartiniAnnotationCallback<>(Given.class, GivenContainer.class, configurable))
            .add(new MartiniAnnotationCallback<>(And.class, AndContainer.class, configurable))
            .add(new MartiniAnnotationCallback<>(When.class, WhenContainer.class, configurable))
            .add(new MartiniAnnotationCallback<>(Then.class, ThenContainer.class, configurable)).build();
}