Created
June 5, 2013 06:07
-
-
Save wendelicious/5711923 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.infusionsoft.metrics.aspect; | |
import com.infusion.util.ListFactory; | |
import com.infusionsoft.metrics.annotations.MetricsAware; | |
import org.springframework.aop.TargetSource; | |
import org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator; | |
import org.springframework.beans.BeansException; | |
import org.springframework.core.annotation.AnnotationUtils; | |
import org.springframework.stereotype.Component; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.stereotype.Repository; | |
import org.springframework.stereotype.Service; | |
import javax.annotation.PostConstruct; | |
import java.lang.annotation.Annotation; | |
import java.util.List; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: wendel.schultz | |
* Date: 6/4/13 | |
* Time: 10:22 PM | |
*/ | |
public class MetricsAnnotatedAutoProxyCreator extends AbstractAutoProxyCreator { | |
private final List<Class<? extends Annotation>> annotations = ListFactory.newLinkedList(); | |
@PostConstruct | |
public void postConstruct(){ | |
annotations.add(Component.class); | |
annotations.add(Controller.class); | |
annotations.add(Service.class); | |
annotations.add(Repository.class); | |
annotations.add(MetricsAware.class); | |
} | |
@Override | |
protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String beanName, TargetSource customTargetSource) throws BeansException { | |
for(Class<? extends Annotation> annotation: annotations){ | |
if (AnnotationUtils.findAnnotation(beanClass, annotation) != null) { | |
return PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS; | |
} | |
} | |
return DO_NOT_PROXY; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment