1

i am using following config in my spring context.xml to register patterns for Java melody configuration. i want to move this out as a spring bean. can anyone help me with this? i am having trouble setting it up properly.

 <bean id="facadeMonitoringAdvisor" class="net.bull.javamelody.MonitoringSpringAdvisor">
        <property name="pointcut">
                <bean class="org.springframework.aop.support.JdkRegexpMethodPointcut">
                        <property name="patterns" value="com.abc.service.*.*(..)" />
                        <property name="excludedPatterns" value="com.abc.service.*.getEntityManager(),com.abc.service.xyz.integration.gateway.*,com.abc.service.xyz.webservice.*" />
                </bean>
        </property>
</bean>
Ashish Thukral
  • 1,445
  • 1
  • 16
  • 26
  • 1
    what do you mean by "move this out as a spring bean"? The sample you pasted in fact is a spring bean configuration. Do you mean you want to configure this as `Annotation`? – sakura Mar 13 '14 at 17:43
  • yes, sorry if i was not clear. i want to move it out to a java pojo config class, where using annotation i can create the bean. – Ashish Thukral Mar 13 '14 at 17:48
  • then I suppose your question is little broad, you need to start first and if you face some problem (**specific problem**) you can come back. To start with you might want to look something like this http://www.mkyong.com/spring3/spring-aop-aspectj-annotation-example/ – sakura Mar 13 '14 at 17:52
  • You want to write a `@Bean` method within a `@Configuration` class? – Sotirios Delimanolis Mar 13 '14 at 17:55
  • yes @ Bean in @ Configuration class. i want an equivalent of the xml form. – Ashish Thukral Mar 13 '14 at 17:59

2 Answers2

1

You should create a @Configuration class. For each bean tag in xml, create a method annotated with @Bean. In this case it would look something like this:

@Configuration
public class MonitoringContext
{
    @Bean(name="facadeMonitoringAdvisor")
    public MonitoringSpringAdvisor getMonitoringSpringAdvisor() {
         MonitoringSpringAdvisor msa = new MonitoringSpringAdvisor();
         msa.setPointcut(getJdkRegexpMethodPointcut());
         return msa;
    }

    @Bean
    public JdkRegexpMethodPointcut getJdkRegexpMethodPointcut() {
         JdkRegexpMethodPointcut jrm = new JdkRegexpMethodPointcut();
         jrm.setPatterns("com.abc.service.*.*(..)");
         jrm.setExcludedPatterns("com.abc.service.*.getEntityManager(),com.abc.service.xyz.integration.gateway.*,com.abc.service.xyz.webservice.*");
         return jrm;
    }
}
Avi
  • 21,182
  • 26
  • 82
  • 121
0

Check out the Spring documentation for AOP here

geoand
  • 60,071
  • 24
  • 172
  • 190