Announcement Announcement Module
Collapse
No announcement yet.
Intercepting Spring Core classes Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #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.

    Comment


    • #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

      Comment


      • #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.

        Comment


        • #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

          Comment


          • #6
            Why not simply use a logging jdbc wrapper?! Those are around the internet and serve your purpose without hacking around yourself?

            Comment


            • #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

              Comment


              • #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).

                Comment


                • #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

                  Comment

                  Working...
                  X