Announcement Announcement Module
Collapse
No announcement yet.
Simple Regular expression problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple Regular expression problem

    hello,

    I've written an interceptor for caching,
    and try to assigned it to some of my service methods,
    I want to do that with the least xml in applicationContext.xml
    I want to use RegexpMethodPointcutAdvisor, and give the full name of the method like:
    mypackage.MyClass.myMethod

    and it doesn't work if I don't specify both Interface and Implementation class.

    see my xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    <beans default-autowire="byName">

    <bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy .DefaultAdvisorAutoProxyCreator"/>

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="location">
    <value>classpath:/jdbc.properties</value>
    </property>
    </bean>


    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName">
    <value>${jdbc.driverClassName}</value>
    </property>
    <property name="url">
    <value>${jdbc.url}</value>
    </property>
    <property name="username">
    <value>${jdbc.username}</value>
    </property>
    <property name="password">
    <value>${jdbc.password}</value>
    </property>
    </bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSess ionFactoryBean">
    <property name="dataSource">
    <ref local="dataSource"/>
    </property>
    <property name="mappingResources">
    <list>
    <value>test/User.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
    <prop key="hibernate.cache.provider_class">net.sf.hibern ate.cache.EhCacheProvider</prop>
    <prop key="hibernate.cache.use_query_cache">true</prop>
    </props>
    </property>
    </bean>

    <bean id="userDao" class="test.UserDaoImpl"/>
    <bean id="userService" class="test.UserServiceImpl"/>


    <bean id="cachePointCutAdvisor" class="org.springframework.aop.support.RegexpMetho dPointcutAdvisor">
    <property name="advice">
    <bean class="org.springframework.aop.interceptor.cache.M emoryCacheInterceptor"/>
    </property>
    <property name="patterns">
    <list>
    <value>test.UserService.getUsers</value>
    <value>test.UserServiceImpl.getUsers</value>
    </list>
    </property>
    </bean>
    </beans>

    Write both interface and implementation class doesn't seem good practice...
    Has anyone experience such thing?

    thanks.

  • #2
    Take a look at Caching the result of methods using Spring and EHCache. This does not answer your question, but it may help.

    Comment


    • #3
      I'm having this problem as well. I want to intercept calls on a particular implementation of a method that is defined in an interface. However unless I specify both the interface and the implementing class in the pointcut regexp. It doesn't work. Is this intentional?

      Here is the my basic configuration:
      Code:
      <bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" />
      
      <bean id="connectionAdvice" class="foo.ConnectionAdvice"/>
      
      <bean id="connectionAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
          <property name="advice">
              <ref bean="connectionAdvice" />
          </property>
          <property name="patterns">
              <list>
                  <!-- see details below -->
                  ...
              </list>
          </property>
      </bean>
      Now lets say I have an interface "foo.Something" that defines a method "doSomething". Now I implement "foo.SomethingImpl which implements this interface. I want to intercept calls to SomethingImpl.doSomething. Specifying the implementation class method in the RegexpMethodPointcutAdvisor patterns does not work:
      Code:
      <value>foo\.SomethingImpl\.doSomething</value>
      Neither does specifying the interface class method:
      Code:
      <value>foo\.Something\.doSomething</value>
      However if I specify both, it works:
      Code:
      <value>foo\.Something\.doSomething</value>
      <value>foo\.SomethingImpl\.doSomething</value>
      Am I missing something here?

      Comment


      • #4
        I have reported this bug and it has been fixed on version 1.1.4.

        Comment

        Working...
        X