Reputation: 839
I have the following bean declared for one particular dao method to use a different data source than the rest of the project.
@Bean(name="kingsDataSource")
public DataSource kingsDataSource(){
JndiDataSourceLookup jndi = new JndiDataSourceLookup();
jndi.setResourceRef(true);
return jndi.getDataSource("dataSource/kings");
Here's the use of that bean.
@Resource(name="kingsDataSource")
private DataSource ds;
Here's from the context.xml (omitting the user and password, which have been verified to be correct, and would have been throwing a different error if they were wrong anyway.) I have also played with putting this in the context.xml of the server, having it in one place and not the other, and having it in both places.
<Resource
name="dataSource/kings"
auth="Container"
type="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
factory="org.apache.naming.factory.BeanFactory"
URL="jdbc:mysql://kings/db_netlogs" />
The error is a name not found exception -
Caused by: javax.naming.NameNotFoundException: Name [dataSource/kings] is
not bound in this Context. Unable to find [dataSource].
My question, then, is - to what do I bind this and how?
Upvotes: 0
Views: 1500
Reputation: 4158
try to add a resource-ref
to your web.xml
<resource-ref>
<res-ref-name>dataSource/kings</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
Upvotes: 1