Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 是否可以多次定义aop:aspectj autoproxy元素_Java_Spring_Spring Aop - Fatal编程技术网

Java 是否可以多次定义aop:aspectj autoproxy元素

Java 是否可以多次定义aop:aspectj autoproxy元素,java,spring,spring-aop,Java,Spring,Spring Aop,我有一个根项目,我不能更改,因为它是其他项目的基础项目。它使用aop:aspectj autoproxy元素在spring配置中定义了aop拦截器 我还有一个项目继承了基础项目,需要用aop定义自己的拦截器:aspectj autoproxy,类似这样: <aop:aspectj-autoproxy > <aop:include name="myInterceptor"/> </aop:aspectj-autoproxy> 但我测试了它,这是不可

我有一个根项目,我不能更改,因为它是其他项目的基础项目。它使用aop:aspectj autoproxy元素在spring配置中定义了aop拦截器

我还有一个项目继承了基础项目,需要用aop定义自己的拦截器:aspectj autoproxy,类似这样:

<aop:aspectj-autoproxy >
    <aop:include name="myInterceptor"/>
</aop:aspectj-autoproxy>

但我测试了它,这是不可能的。只考虑基本项目中的第一个配置,我无法移动或修改它


在这种情况下,如何定义拦截器?是否可以以某种方式合并这两种配置?

您可以使用
BeanFactoryPostProcessor
添加包含模式,例如:

public class AspectJAutoProxyConfigurer implements BeanFactoryPostProcessor {

    private String[] includePatterns;

    @SuppressWarnings({ "rawtypes", "unchecked" })
    @Override
    public void postProcessBeanFactory(
            ConfigurableListableBeanFactory beanFactory) throws BeansException {

        BeanDefinition beanDef = beanFactory.getBeanDefinition(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
        ManagedList includes = (ManagedList) 
                beanDef.getPropertyValues().get("includePatterns");

        for (String includePattern : this.includePatterns)
            includes.add(new TypedStringValue(includePattern));

    }

    public String[] getIncludePatterns() {
        return includePatterns;
    }

    public void setIncludePatterns(String[] includePatterns) {
        this.includePatterns = includePatterns;
    }

}


<bean id="autoProxyCreatorConfigurer" class="AspectJAutoProxyConfigurer">
    <property name="includePatterns" value="one,two,three" />
</bean>
公共类aspectjautoproxyconfiguer实现BeanFactoryPostProcessor{
私有字符串[]包含模式;
@SuppressWarnings({“rawtypes”,“unchecked”})
@凌驾
公共无效后处理BeanFactory(
ConfigurableListableBeanFactory(beanFactory)引发BeanException{
BeanDefinition BeanDefinition=beanFactory.getBeanDefinition(AopConfigUtils.AUTO\u PROXY\u CREATOR\u BEAN\u NAME);
ManagedList包含=(ManagedList)
beanDef.getPropertyValues().get(“includePatterns”);
for(字符串includePattern:this.includePatterns)
includes.add(新类型字符串值(includePattern));
}
公共字符串[]getIncludePatterns(){
返回includePatterns;
}
公共void集合includePatterns(字符串[]includePatterns){
this.includePatterns=includePatterns;
}
}