-
May 19th, 2012, 11:17 PM
#1
Intercepting Spring Core classes
Hi everyone, I'm trying to intercept an unmapped bean. Actually, I'm trying to intercept query methods in NamedParameterJdbcOperations and JdbcOperations implementations. Note that my JdbcTemplates classes isn't a mapped bean, but using internal method getXXXJdbcTemplate in XXXDaoSupport class.
Is possible create a MethodInterceptor to intercept the queryXXX methods?
Thanks
Josivan
-
May 21st, 2012, 01:46 AM
#2
No. Spring AOP only allows for interception of external method calls on registered beans. If it is more you want use loadtime or compile timeweaving.
-
May 21st, 2012, 02:02 PM
#3
I've tried to do something like this:
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
<property name="dataSource" ref="dataSource" />
</bean>
Then, I've created a method interceptor to jdbcTemplate bean.
Now, I've this message:
Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy0 implementing org.springframework.jdbc.core.JdbcOperations,org.s pringframework.beans.factory.InitializingBean,org. springframework.aop.SpringProxy,org.springframewor k.aop.framework.Advised] to required type [org.springframework.jdbc.core.JdbcTemplate] for property 'jdbcTemplate'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy0 implementing org.springframework.jdbc.core.JdbcOperations,org.s pringframework.beans.factory.InitializingBean,org. springframework.aop.SpringProxy,org.springframewor k.aop.framework.Advised] to required type [org.springframework.jdbc.core.JdbcTemplate] for property 'jdbcTemplate': no matching editors or conversion strategy found
What can I try to intercept that?
tks
Josivan
-
May 22nd, 2012, 01:02 AM
#4
I suggest a read of the reference guide especially the part that explains AOP and how that is applied in Spring.
In short you will get an object that acts like an object implementing all interfaces of the JdbcTemplate (you could use JdbcOperations) if you want something else use classbased proxies but this requires cglib on the classpath.
Also why do you want to intercept the jdbctemplate methods? If it is for the queries etc. there are better options.
-
May 22nd, 2012, 07:12 AM
#5
Hi, The idea is capture the parameters sent to all queries invocation. To print sql commands, the log is perfect. But I need get all parameters, without map each bean or method bean to intercept. Then I thought that intercepting the JdbcTemplate method invocation shall solve my problem.
I'll trying, if I solve I'll post here.
Thanks a lot
Josivan
-
May 22nd, 2012, 07:14 AM
#6
Why not simply use a logging jdbc wrapper?! Those are around the internet and serve your purpose without hacking around yourself?
-
May 22nd, 2012, 07:38 AM
#7
Hi, unfortunatelly I can't use some libs. Here, at my company, exists a list with acceptable frameworks (called green list or white list itens). Spring is ok for me, but others no.
Thanks again
Josivan
-
May 22nd, 2012, 07:47 AM
#8
So instead of using a widely adopted and available wrapper (which you can install and configure under 1h) you spend days in hacking around and (re)inventing your own... Very wise... I would try and convince them otherwise...
(Or take a look at those frameworks and use that information to write your own wrapper which gives you a solution which works with everything from JPA to plain JDBC).
-
May 22nd, 2012, 08:05 AM
#9
I agree with you. But here, some things are really complicated. Is a closed world. The easy way is to say: I can't implement this requirement. Maybe I do it. 
Josivan
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules