简体   繁体   中英

@Bean configuration instead of context.xml

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>

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

在此处查看AOP的Spring文档

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM