Java Ninja Chronicles By Norris Shelton

Things I learned in the pursuit of code

My production Springframework code doesn’t normally need to get the datasource directly because I choose to inject the template. However, sometimes there is a need to get the datasource.

The datasource is usually defined as

<jee:jndi-lookup id="jxportalDs" jndi-name="jdbc/jxportal"/>

If you try to inject that with

    @Resource(name = "jxportalDs")
    private DataSource dataSource;

You will get compile problems because the the code declares a type of DataSource, but there is not a type declared for Datasource. This can be fixed by adding a type to your jndi declaration

<jee:jndi-lookup id="jxportalDs" jndi-name="jdbc/jxportal" expected-type="javax.sql.DataSource"/>

December 6th, 2011

Posted In: Java, Spring

Leave a Reply

Your email address will not be published. Required fields are marked *

WP to LinkedIn Auto Publish Powered By : XYZScripts.com