Reputation: 10146
I am using Weblogic 12c and I have configured my datasources like this:
Notice that they are all deployed on target "AdminServer". Also, the "Name" field and "JNDI Name" field are identical. For example, suppose one datasource's name is "MYDS".
Now, when I try to acquire that datasource through Spring Data JPA like this:
@Bean
@Primary
public DataSource businessDataSource() throws IllegalArgumentException, NamingException {
JndiObjectFactoryBean dataSource = new JndiObjectFactoryBean();
dataSource.setResourceRef(true);
dataSource.setJndiName("MYDS");
dataSource.afterPropertiesSet();
return (DataSource) dataSource.getObject();
}
I get the following error when trying to deploy the war file to weblogic:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'businessDataSource' threw exception; nested exception is javax.naming.NameNotFoundException: Unable to resolve 'MYDS'. Resolved ''; remaining name 'MYDS'
Also I see this error:
DEBUG o.s.jndi.JndiObjectFactoryBean - Converted JNDI name [java:comp/env/MYDS] not found - trying original name [MYDS]. javax.naming.NameNotFoundException: While trying to look up comp/env/MYDS in /app/myapp/webclient/404708050.; remaining name 'comp/env/MYDS'
Upvotes: 0
Views: 1214
Reputation: 920
Just looking at the source for setResourceRef and it states :
public void setResourceRef(boolean resourceRef)
Set whether the lookup occurs in a Java EE container,
i.e. if the prefix "java:comp/env/" needs to be added if the JNDI name doesn't already contain it. Default is "false".
Note: Will only get applied if no other scheme (e.g. "java:") is given.
If you are setting it to true have you tried adding java:comp/env/ to the JNDI name ?
Upvotes: 1