Closed
Description
We are trying to use the JndiObjectFactoryBean to retrieve our Datasources following the pattern of the jee tag for Spring Boot and getting the following exception:
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource()] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:188)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:586)
... 274 common frames omitted
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)Caused by: org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.getDriverClassName(DataSourceProperties.java:93)
at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource(DataSourceAutoConfiguration.java:105)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
The following code works fine:
@Bean(destroyMethod = "")
public DataSource dataSource() {
return (DataSource) new JndiObjectFactoryBean() {{
setExpectedType(DataSource.class);
setResourceRef(true);
setJndiName("jndiDatasource");
try {
afterPropertiesSet();
} catch (Exception e) {
e.printStackTrace();
}
}}.getObject();
}
But the code below throws the exception above:
@Bean
public JndiObjectFactoryBean dataSource() {
return new JndiObjectFactoryBean() {{
setExpectedType(DataSource.class);
setResourceRef(true);
setJndiName("jndiDatasource");
}};
}
From looking at the source a bit, it would seem that the @ConditionalOnMissingBean does not also check the FactoryBean return type. We also tried using the jee tag within the XML and including that but it still gave the error above. This looks similar to #352 and #355 but wanted to report this. We are running in Weblogic 12c and had to add the destroyMethod="" as without it it was unbinding the Datasource on undeploy.