Example usage for org.springframework.beans.factory.config AutowireCapableBeanFactory AUTOWIRE_BY_TYPE

List of usage examples for org.springframework.beans.factory.config AutowireCapableBeanFactory AUTOWIRE_BY_TYPE

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config AutowireCapableBeanFactory AUTOWIRE_BY_TYPE.

Prototype

int AUTOWIRE_BY_TYPE

To view the source code for org.springframework.beans.factory.config AutowireCapableBeanFactory AUTOWIRE_BY_TYPE.

Click Source Link

Document

Constant that indicates autowiring bean properties by type (applying to all bean property setters).

Usage

From source file:com.github.bfour.fpliteraturecollector.application.Application.java

public static void main(String[] args) {

    try {/*from w w w  .  ja  va2 s  .co  m*/

        // https://vvirlan.wordpress.com/2014/12/10/solved-caused-by-java-awt-headlessexception-when-trying-to-create-a-swingawt-frame-from-spring-boot/
        SpringApplicationBuilder builder = new SpringApplicationBuilder(Application.class);
        builder.headless(false);
        ConfigurableApplicationContext context = builder.run(args);

        // Neo4jResource myBean = context.getBean(Neo4jResource.class);
        // myBean.functionThatUsesTheRepo();

        // ServiceManager servMan = ServiceManager
        // .getInstance(ServiceManagerMode.TEST);
        ServiceManager servMan = context.getBean(ServiceManager.class);
        context.getAutowireCapableBeanFactory().autowireBeanProperties(servMan,
                AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);

        FPJGUIManager.getInstance().initialize();

        MainWindow.getInstance(servMan).setVisible(true);

    } catch (BeanCreationException e) {
        e.printStackTrace();
        if (ExceptionUtils.getRootCause(e) instanceof IOException)
            ApplicationErrorDialogue.showMessage("Sorry, could not access the database.\n"
                    + "This might be because it is currently in use or because there are insufficient access rights.\n"
                    + "Try closing all running instances of this application and restart.");
        else
            ApplicationErrorDialogue.showDefaultMessage(e, BUG_REPORT_URL);
    } catch (Exception e) {
        e.printStackTrace();
        ApplicationErrorDialogue.showDefaultMessage(e, BUG_REPORT_URL);
    }

}

From source file:org.fcrepo.upgrade.utils.TechnicalMetadataMigrator.java

/**
 * Migrate technical metadata./*from  w  w  w . j a  va 2s  . c o m*/
 * @param args If "dryrun" is passed as an argument, the utility will print out what would be done,
 *             but no changes will be made.
**/
public static void main(final String[] args) {
    ConfigurableApplicationContext ctx = null;
    try {
        final boolean dryrun;
        if (args.length > 0 && "dryrun".equals(args[0])) {
            dryrun = true;
        } else {
            dryrun = false;
        }

        final TechnicalMetadataMigrator migrator = new TechnicalMetadataMigrator();
        ctx = new ClassPathXmlApplicationContext("classpath:/spring/master.xml");
        ctx.getBeanFactory().autowireBeanProperties(migrator, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE,
                false);
        migrator.run(dryrun);

    } catch (RepositoryException ex) {
        ex.printStackTrace();
    } finally {
        if (null != ctx) {
            ctx.close();
        }
    }
}

From source file:org.parancoe.example.util.ApplicationContextHolder.java

public static void autowireBeanProperties(Object o) {
    context.getBeanFactory().autowireBeanProperties(o, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
}

From source file:net.noctuasource.act.spring.SpringBeanInjector.java

@Override
public void inject(Object object) {
    applicationContext.getAutowireCapableBeanFactory().autowireBeanProperties(object,
            AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
}

From source file:io.acme.solution.application.conf.CommandHandlerUtils.java

public static Map<String, CommandHandler> buildCommandHandlersRegistry(final String basePackage,
        final ApplicationContext context) {

    final Map<String, CommandHandler> registry = new HashMap<>();
    final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
            false);//  w  ww  . j a v a 2s  .  c  o  m
    final AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory();
    scanner.addIncludeFilter(new AssignableTypeFilter(CommandHandler.class));

    CommandHandler currentHandler = null;

    for (BeanDefinition bean : scanner.findCandidateComponents(basePackage)) {
        currentHandler = (CommandHandler) beanFactory.createBean(
                ClassUtils.resolveClassName(bean.getBeanClassName(), context.getClassLoader()),
                AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
        registry.put(currentHandler.getInterest(), currentHandler);
    }

    return registry;
}

From source file:org.apache.cloudstack.ldap.LdapUserManagerFactory.java

public LdapUserManager getInstance(LdapUserManager.Provider provider) {
    LdapUserManager ldapUserManager;/*  w  w w  .j  a v a 2  s .  co m*/
    if (provider == LdapUserManager.Provider.MICROSOFTAD) {
        ldapUserManager = ldapUserManagerMap.get(LdapUserManager.Provider.MICROSOFTAD);
        if (ldapUserManager == null) {
            ldapUserManager = new ADLdapUserManagerImpl();
            applicationCtx.getAutowireCapableBeanFactory().autowireBeanProperties(ldapUserManager,
                    AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
            ldapUserManagerMap.put(LdapUserManager.Provider.MICROSOFTAD, ldapUserManager);
        }
    } else {
        //defaults to openldap
        ldapUserManager = ldapUserManagerMap.get(LdapUserManager.Provider.OPENLDAP);
        if (ldapUserManager == null) {
            ldapUserManager = new OpenLdapUserManagerImpl();
            applicationCtx.getAutowireCapableBeanFactory().autowireBeanProperties(ldapUserManager,
                    AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
            ldapUserManagerMap.put(LdapUserManager.Provider.OPENLDAP, ldapUserManager);
        }
    }
    return ldapUserManager;
}

From source file:de.zib.vold.Test.ClientTest.java

@BeforeClass(groups = { "VoldServiceTest" })
public void init() {
    voldClient = (VolDClient) context.getAutowireCapableBeanFactory().createBean(VolDClient.class,
            AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
    voldClient.setBaseURL(baseUrl);//from  w w w  .j  a v  a 2 s  .co  m

    fillKeys();
}

From source file:com.mb.framework.web.filter.ReqRespLoggerFilter.java

/**
 * /*  w ww.  j a v  a  2  s .  co m*/
 * This method is not implemented
 */
@Override
public void init(FilterConfig filterConfig) throws ServletException {

    ServletContext servletContext = filterConfig.getServletContext();

    WebApplicationContext webApplicationContext = WebApplicationContextUtils
            .getWebApplicationContext(servletContext);

    AutowireCapableBeanFactory autowireCapableBeanFactory = webApplicationContext
            .getAutowireCapableBeanFactory();

    autowireCapableBeanFactory.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);

    logger.trace("This method implementation not needed");
}

From source file:org.caratarse.auth.services.spring.ApplicationContextHolder.java

public void autowireBeanProperties(Object o) {
    context.getBeanFactory().autowireBeanProperties(o, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
}