Category: Spring Framework Gene De Lisa @ 10:42 am —
1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5 out of 5)
Loading ... Loading ...

Let’s say you wrap stored procedures with Spring’s StoredProcedure class like this:

@Repository

public class SPGetWhatever extends StoredProcedure {

   @Autowired

   public SPGetWhatever (DataSource dataSource)etc.

That @Repository annotation like @Component and @Service allows you to tell Spring to scan the
classpath and instantiate them without you having to write a bean element in your Spring XML file.
You can even inject dependencies like the DataSource with the @Autowired annotation as you see here.

You enable it with this in your XML config file:

schema stuff...

<context:annotation-config />

<context:component-scan base-package="com.rockhoppertech.someproject" />
setup the datasource etc.

It will recursively scan the package you specify for these annotations. You will get a bean in your context
with the simple classname. (You can override that if you want).

N.B. this used to be aop:component-scan but it was moved.

Then in some DAO you can do this:

@Repository

public class MyDaoImpl implements MyDao {

@Autowired(required=true)

SPGetWhatever sp;

Pretty cool. Unless you use AOP - and hey, you’re just not hip and happenin’ if you’re not right?

<aop:aspectj-autoproxy/>

Turn the logging level up and you will indeed see Spring create the SP. But then it will fail when creating your
DaoImpl saying that there is no bean that satisfied the dependency on the SP class. But two lines above that
it just said it has the bean in the context. WTF?

Here’s a clue. Do this:

<aop:aspectj-autoproxy proxy-target-class="true"/>

You’ll see that Spring’s StoredProcedure class does not have a default constructor so there is a problem creating the proxy.

What RJ says in his Intro to Spring 2.5 article about StoredProcedures is that you can have them implement an interface blah blah fishcake…
Something like this.

@Repository

public class SPGetWhatever extends StoredProcedure implements SomeBloodyInterface {

etc.

Sure enough that solves the problem. OK, interfaces are good.
A glass of wine is good too. Drinking a vat of wine will kill you.

Sorry, no comments yet.

Write Your Comment

Comment Guidelines: Basic XHTML is allowed (a href, strong, em, code). All line breaks and paragraphs will be generated automatically.

You should have a name, right? 
Your email address, I promised I won't tell it to anyone. 
If you have a web site or blog, you can type the URL right here. 
This is where you type your comments. 
Remember my information for the next time I visit.