Example usage for org.springframework.jndi JndiObjectFactoryBean getObject

List of usage examples for org.springframework.jndi JndiObjectFactoryBean getObject

Introduction

In this page you can find the example usage for org.springframework.jndi JndiObjectFactoryBean getObject.

Prototype

@Override
@Nullable
public Object getObject() 

Source Link

Document

Return the singleton JNDI object.

Usage

From source file:com.zekke.webapp.config.DataSourceConfig.java

/**
 * Creates a new DataSource./*from  w ww. j a  va2s.c  o m*/
 *
 * @param jndiName the JNDI resource.
 * @return a DataSource.
 * @throws NamingException if the given JNDI resource doesn't exist.
 */
@Bean
public DataSource dataSource(@Value("${jndi.name}") String jndiName) throws NamingException {
    JndiObjectFactoryBean jndiFactoryBean = new JndiObjectFactoryBean();
    jndiFactoryBean.setJndiName(jndiName);
    jndiFactoryBean.afterPropertiesSet();
    return (DataSource) jndiFactoryBean.getObject();
}

From source file:net.sourceforge.vulcan.jabber.JdbcScreenNameMapper.java

protected DataSource findDataSource() throws IllegalArgumentException, NamingException {
    final JndiObjectFactoryBean dsFactory = new JndiObjectFactoryBean();
    dsFactory.setJndiName(config.getJndiName());
    dsFactory.afterPropertiesSet();// www.  ja v  a  2  s  .  co  m

    return (DataSource) dsFactory.getObject();
}

From source file:com.edgenius.core.service.impl.JavaMailSenderImpl.java

/**
 * MailSession JDNI name changed, reload JNDI object. 
 * //from   www .  j a  v  a  2  s  . com
 */
public void resetMailSessionByJNDI(String jndiName) throws IllegalArgumentException, NamingException {
    //always reset session to null, so make "reset" meaningful. This is also a trick, as setSession() doesn't allow null
    //however, this.setJavaMailProperties(prop) will reset Session to null internally...
    this.setJavaMailProperties(new Properties());

    JndiObjectFactoryBean factory = new JndiObjectFactoryBean();
    factory.setJndiName(jndiName);
    factory.afterPropertiesSet();
    if (factory.getObject() instanceof Session)
        this.setSession((Session) factory.getObject());
    else
        throw new IllegalArgumentException("JNDI object is not mail session instance");
}

From source file:com.evolveum.midpoint.repo.sql.DataSourceFactory.java

private DataSource createJNDIDataSource() throws IllegalArgumentException, NamingException {
    JndiObjectFactoryBean factory = new JndiObjectFactoryBean();
    factory.setJndiName(configuration.getDataSource());
    factory.afterPropertiesSet();/*from   w  ww  . ja v a2  s. c  o  m*/

    return (DataSource) factory.getObject();
}

From source file:sample.tomcat.jndi.Application.java

@Bean(destroyMethod = "")
public DataSource jndiDataSource() throws IllegalArgumentException, NamingException {
    System.out.println("\n\n\nIn jndiDataSource\n\n\n");
    JndiObjectFactoryBean bean = new JndiObjectFactoryBean();
    bean.setJndiName("jdbc/MYDataSource");
    bean.setProxyInterface(DataSource.class);
    bean.setLookupOnStartup(false);/*  w  ww.  j  a va 2 s .c  o m*/
    bean.afterPropertiesSet();
    return (DataSource) bean.getObject();
}

From source file:sample.tomcat.jndi.SampleTomcatJndiApplication.java

@Bean(destroyMethod = "")
public DataSource jndiDataSource() throws IllegalArgumentException, NamingException {
    JndiObjectFactoryBean bean = new JndiObjectFactoryBean();
    bean.setJndiName("java:comp/env/jdbc/myDataSource");
    bean.setProxyInterface(DataSource.class);
    bean.setLookupOnStartup(false);//from   w  w  w  . ja va  2 s . c  o  m
    bean.afterPropertiesSet();
    return (DataSource) bean.getObject();
}

From source file:com.redhat.rhtracking.config.JPAConfig.java

@Bean
public DataSource jndiDataSource() throws NamingException {
    JndiObjectFactoryBean factory = new JndiObjectFactoryBean();
    factory.setJndiName("java:/jdbc/rhtracking");
    factory.setLookupOnStartup(true);// w ww . j  a v  a 2 s  . c  om
    factory.setProxyInterface(DataSource.class);
    factory.afterPropertiesSet();

    return (DataSource) factory.getObject();
}

From source file:dk.nsi.haiba.minipasconverter.config.MinipasConverterConfiguration.java

@Bean
public DataSource minipasDataSource() throws Exception {
    JndiObjectFactoryBean factory = new JndiObjectFactoryBean();
    factory.setJndiName(minipasJNDIName);
    factory.setExpectedType(DataSource.class);
    factory.afterPropertiesSet();//from w  w  w .j  a v a 2 s.  c o  m
    return (DataSource) factory.getObject();
}

From source file:com.github.dbourdette.glass.SpringConfig.java

@Bean
public DataSource dataSource() throws Exception {
    if (configuration().isInMemory()) {
        return null;
    }//from w  w w.j  ava2 s  .c om

    JndiObjectFactoryBean factoryBean = new JndiObjectFactoryBean();

    factoryBean.setJndiName("java:comp/env/jdbc/glassDb");

    factoryBean.afterPropertiesSet();

    return (DataSource) factoryBean.getObject();
}

From source file:dk.nsi.haiba.minipasconverter.config.MinipasConverterConfiguration.java

@Bean
public DataSource haibaDataSource() throws Exception {
    JndiObjectFactoryBean factory = new JndiObjectFactoryBean();
    factory.setJndiName(haibaJNDIName);/*ww w . j a v a 2  s  .  c  om*/
    factory.setExpectedType(DataSource.class);
    factory.afterPropertiesSet();
    DataSource dataSource = (DataSource) factory.getObject();
    // requires manual transaction handling
    dataSource.getConnection().setAutoCommit(false);
    return dataSource;
}