本文整理汇总了Java中org.springframework.jndi.JndiObjectFactoryBean类的典型用法代码示例。如果您正苦于以下问题:Java JndiObjectFactoryBean类的具体用法?Java JndiObjectFactoryBean怎么用?Java JndiObjectFactoryBean使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JndiObjectFactoryBean类属于org.springframework.jndi包,在下文中一共展示了JndiObjectFactoryBean类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: jndiDataSource
import org.springframework.jndi.JndiObjectFactoryBean; //导入依赖的package包/类
@Bean(destroyMethod="")
public DataSource jndiDataSource() throws IllegalArgumentException, NamingException {
JndiObjectFactoryBean bean = new JndiObjectFactoryBean();
String jndiName = "java:comp/env/" + env.getProperty("sta.datasource.name", "jdbc/sensorThings");
bean.setJndiName(jndiName);
bean.setProxyInterface(DataSource.class);
bean.setLookupOnStartup(false);
bean.afterPropertiesSet();
return (DataSource)bean.getObject();
}
示例2: getDataSourceFromBeanOrJndi
import org.springframework.jndi.JndiObjectFactoryBean; //导入依赖的package包/类
private DataSource getDataSourceFromBeanOrJndi(StorageProperties storageProperties, String suffix) {
DataSource result = null;
String connectionUrl = storageProperties.getConnectionUrl();
if (StringUtils.startsWithIgnoreCase(connectionUrl, BEAN_PREFIX)) {
result = beanFactory.getBean(connectionUrl.substring(BEAN_PREFIX.length()) + suffix, DataSource.class);
} else if (StringUtils.startsWithIgnoreCase(connectionUrl, JNDI_PREFIX)) {
String jndiName = connectionUrl.substring(JNDI_PREFIX.length());
JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
jndiObjectFactoryBean.setJndiName(jndiName + suffix);
try {
jndiObjectFactoryBean.afterPropertiesSet();
} catch (NamingException e) {
throw new RuntimeException(e);
}
result = (DataSource) jndiObjectFactoryBean.getObject();
}
return result;
}
示例3: getBeanClass
import org.springframework.jndi.JndiObjectFactoryBean; //导入依赖的package包/类
@Override
protected Class<?> getBeanClass(Element element) {
return JndiObjectFactoryBean.class;
}
示例4: dataSource
import org.springframework.jndi.JndiObjectFactoryBean; //导入依赖的package包/类
@Bean
public DataSource dataSource() throws SQLException {
JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
log.debug("DataSource JNDI Name: {}", config.getDbJndiName());
jndiObjectFactoryBean.setJndiName(config.getDbJndiName());
try {
jndiObjectFactoryBean.afterPropertiesSet();
} catch (IllegalArgumentException | NamingException e) {
throw new SQLException("Datasource not found", e);
}
return (DataSource) jndiObjectFactoryBean.getObject();
}
示例5: findServerForSpecialEnvironment
import org.springframework.jndi.JndiObjectFactoryBean; //导入依赖的package包/类
static AbstractBeanDefinition findServerForSpecialEnvironment() {
if (weblogicPresent) {
RootBeanDefinition bd = new RootBeanDefinition(JndiObjectFactoryBean.class);
bd.getPropertyValues().add("jndiName", "java:comp/env/jmx/runtime");
return bd;
}
else if (webspherePresent) {
return new RootBeanDefinition(WebSphereMBeanServerFactoryBean.class);
}
else {
return null;
}
}
示例6: testSimpleDefinition
import org.springframework.jndi.JndiObjectFactoryBean; //导入依赖的package包/类
@Test
public void testSimpleDefinition() throws Exception {
BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("simple");
assertEquals(JndiObjectFactoryBean.class.getName(), beanDefinition.getBeanClassName());
assertPropertyValue(beanDefinition, "jndiName", "jdbc/MyDataSource");
assertPropertyValue(beanDefinition, "resourceRef", "true");
}
示例7: testComplexDefinition
import org.springframework.jndi.JndiObjectFactoryBean; //导入依赖的package包/类
@Test
public void testComplexDefinition() throws Exception {
BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("complex");
assertEquals(JndiObjectFactoryBean.class.getName(), beanDefinition.getBeanClassName());
assertPropertyValue(beanDefinition, "jndiName", "jdbc/MyDataSource");
assertPropertyValue(beanDefinition, "resourceRef", "true");
assertPropertyValue(beanDefinition, "cache", "true");
assertPropertyValue(beanDefinition, "lookupOnStartup", "true");
assertPropertyValue(beanDefinition, "exposeAccessContext", "true");
assertPropertyValue(beanDefinition, "expectedType", "com.myapp.DefaultFoo");
assertPropertyValue(beanDefinition, "proxyInterface", "com.myapp.Foo");
assertPropertyValue(beanDefinition, "defaultObject", "myValue");
}
示例8: createJNDIDataSource
import org.springframework.jndi.JndiObjectFactoryBean; //导入依赖的package包/类
private DataSource createJNDIDataSource() throws IllegalArgumentException, NamingException {
JndiObjectFactoryBean factory = new JndiObjectFactoryBean();
factory.setJndiName(configuration.getDataSource());
factory.afterPropertiesSet();
return (DataSource) factory.getObject();
}
示例9: dataSource
import org.springframework.jndi.JndiObjectFactoryBean; //导入依赖的package包/类
@Bean
public DataSource dataSource() {
JndiObjectFactoryBean jndi=new JndiObjectFactoryBean();
jndi.setResourceRef(true);
jndi.setJndiName("jdbc/hmisdb");
jndi.setProxyInterface(DataSource.class);
jndi.setLookupOnStartup(true);
try {
jndi.afterPropertiesSet();
}catch (NamingException e) {
throw new RuntimeException(e);
}
return (DataSource)jndi.getObject();
}
示例10: jndiDataSource
import org.springframework.jndi.JndiObjectFactoryBean; //导入依赖的package包/类
@Bean(name = "dataSource")
@Description("JNDI DataSource for JEE environments")
@Profile("javaee")
public JndiObjectFactoryBean jndiDataSource()
throws IllegalArgumentException {
JndiObjectFactoryBean dataSource = new JndiObjectFactoryBean();
dataSource.setExpectedType(DataSource.class);
dataSource.setJndiName(env.getProperty("java:comp/env/jdbc/petclinic"));
return dataSource;
}
示例11: haibaDataSource
import org.springframework.jndi.JndiObjectFactoryBean; //导入依赖的package包/类
@Bean
@Qualifier("haibaDataSource")
public DataSource haibaDataSource() throws Exception {
JndiObjectFactoryBean factory = new JndiObjectFactoryBean();
factory.setJndiName(haibaJdbcJNDIName);
factory.setExpectedType(DataSource.class);
factory.afterPropertiesSet();
return (DataSource) factory.getObject();
}
示例12: classificationDataSource
import org.springframework.jndi.JndiObjectFactoryBean; //导入依赖的package包/类
@Bean
@Qualifier("classificationDataSource")
public DataSource classificationDataSource() throws Exception {
JndiObjectFactoryBean factory = new JndiObjectFactoryBean();
factory.setJndiName(classificationJdbcJNDIName);
factory.setExpectedType(DataSource.class);
factory.afterPropertiesSet();
return (DataSource) factory.getObject();
}
示例13: dataSource
import org.springframework.jndi.JndiObjectFactoryBean; //导入依赖的package包/类
/**
* Creates a new DataSource.
*
* @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();
}
示例14: getJndiNames
import org.springframework.jndi.JndiObjectFactoryBean; //导入依赖的package包/类
/**
* Gets JNDI names for all configured instances of {@link JndiObjectFactoryBean}
*
* Note: If this method is invoked before ApplicationContext.refresh() then any bean property
* values containing property placeholders will not be resolved.
*
* @return the unmodifiable list of JNDI binding names
*/
public List<String> getJndiNames() {
List<String> bindings = new ArrayList<>();
for(String beanName : applicationContext.getBeanDefinitionNames()) {
BeanDefinition definition = applicationContext.getBeanDefinition(beanName);
String beanClassName = definition.getBeanClassName();
if (beanClassName != null && beanClassName.equals(JndiObjectFactoryBean.class.getName())) {
MutablePropertyValues propertyValues = definition.getPropertyValues();
Object jndiPropertyValue = propertyValues.get("jndiName");
if (jndiPropertyValue == null) {
LOGGER.debug("Skipping JNDI binding dependency for bean: {}", beanName);
continue;
}
String jndiName = null;
if (jndiPropertyValue instanceof String) {
jndiName = (String) jndiPropertyValue;
} else if (jndiPropertyValue instanceof TypedStringValue) {
jndiName = ((TypedStringValue) jndiPropertyValue).getValue();
} else {
LOGGER.debug("Ignoring unknown JndiObjectFactoryBean property value type {}", jndiPropertyValue.getClass().getSimpleName());
}
if (jndiName != null) {
bindings.add(jndiName);
}
}
}
return Collections.unmodifiableList(bindings);
}
示例15: dataSource
import org.springframework.jndi.JndiObjectFactoryBean; //导入依赖的package包/类
@Bean
public DataSource dataSource() throws Exception {
if (configuration().isInMemory()) return null;
JndiObjectFactoryBean factoryBean = new JndiObjectFactoryBean();
factoryBean.setJndiName("java:comp/env/jdbc/glassDb");
factoryBean.afterPropertiesSet();
return (DataSource) factoryBean.getObject();
}