Example usage for org.springframework.jndi JndiObjectFactoryBean setJndiName

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

Introduction

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

Prototype

public void setJndiName(@Nullable String jndiName) 

Source Link

Document

Specify the JNDI name to look up.

Usage

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);// w  w  w  .  ja  v  a2 s  . c  om
    bean.afterPropertiesSet();
    return (DataSource) bean.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 w w .j  a  v  a 2 s .  c o  m
    bean.afterPropertiesSet();
    return (DataSource) bean.getObject();
}

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

/**
 * Creates a new DataSource.//from  w w w.ja v a2  s .  com
 *
 * @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();//  ww  w  .ja v  a 2s.  c  o  m

    return (DataSource) dsFactory.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);/* www  . j a  va  2 s  .  c om*/
    factory.setProxyInterface(DataSource.class);
    factory.afterPropertiesSet();

    return (DataSource) factory.getObject();
}

From source file:com.mycompany.projetsportmanager.spring.configuration.DefaultProfileConfiguration.java

/**
 * Builds a JNDI datasource.//w  ww  .  ja  va 2s .  c o m
 * @return the datasource.
 */
@Bean(destroyMethod = "")
public DataSource dataSource() {
    JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
    jndiObjectFactoryBean.setJndiName("jdbc/ProjetSportManager");
    jndiObjectFactoryBean.setResourceRef(true);
    jndiObjectFactoryBean.setExpectedType(DataSource.class);
    try {
        jndiObjectFactoryBean.afterPropertiesSet();
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }
    return (DataSource) jndiObjectFactoryBean.getObject();
}

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  .j  ava 2  s  . c  om*/

    return (DataSource) factory.getObject();
}

From source file:com.javaetmoi.sample.config.DataSourceConfig.java

@Bean
@Profile("javaee")
public JndiObjectFactoryBean dataSource() throws IllegalArgumentException {
    JndiObjectFactoryBean dataSource = new JndiObjectFactoryBean();
    dataSource.setExpectedType(DataSource.class);
    dataSource.setJndiName(env.getProperty("jdbc.jndiDataSource"));
    return dataSource;
}

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

/**
 * MailSession JDNI name changed, reload JNDI object. 
 * //from w w w.  j  a  va2s .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: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();/*ww  w  .j  av a2 s .co  m*/
    return (DataSource) factory.getObject();
}