Spring jpa:repositories and subpackages

This one has been biting me for a few days; I just had to jot a few notes down about it.

Everywhere you look, the documentation about the <jpa:repositories> spring config element says that the base-package and all subpackages will be scanned for entities that are marked with @Repository (or one of its derived classes). What’s I’ve found is that this just isn’t true. We used:

<jpa:repositories base-package="com.mycompany.foo" .../>

and have a Spring-derived Dao in the com.mycompany.foo.bar package. We end up with an exception in our test case something to the tune of “not an managed type: java.lang.Object”. If, however, we replace the above spring snippet with:

<jpa:repositories base-package="com.mycompany.foo.bar" .../>

then everything is fine.

I wonder if everyone says it scans subpackages, but nobody actually uses it that way?

Note that if you have multiple packages, you can provide a comma-separated list of packages, or (so they say), you can provide a wild-carded base-package. Good luck!

Advertisements

About John Woodward

Principal Consultant at Improving Enterprises, Inc.
This entry was posted in Software and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s