Question

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>
Was it helpful?

Solution

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;
    }
}

OTHER TIPS

Check out the Spring documentation for AOP here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top