Spring slow AOP startup time

We use Spring (3.0.5) AOP with @AspectJand style annotations <aop:aspectj-autoproxy/> . We use it for transactions, auditing, profiling, etc. It works great, except that application startup time is constantly increasing as more code is added.

I did some profiling and found that most of the time is spent initializing the Spring container, more specifically org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(String, ObjectFactory), it takes about 35 seconds. org.springframework.aop.support.AopUtils.canApply(Pointcut, Class, boolean)- takes about 15 seconds.

My goal is for the application to start in 5-10 seconds, rather than ~ 45 seconds, as it is now, so any advice would be greatly appreciated.

+5
source share
6 answers

I had the same problem, it turned out that Spring AOP auto-proxing spends a lot of time loading booting classes using bcel (without caching, so loading the same classes again and again like java.lang.Object ...) when trying to figure out what tips apply. It can be improved somewhat by writing finer-grained Point abbreviations (use internally, for example, @within), but I found a solution that worked better if all your pointcuts were written using @annotation.

1) Deactivate auto proxy with: spring.aop.auto = false

2) AnnotationAwareAspectJAutoProxyCreator beans, , , :

@Override
protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String beanName,   TargetSource targetSource) {
  if (beanClass != null && isInPackages(beansPackages, beanClass.getName()) &&   hasAspectAnnotation(beanClass)) {
    return super.getAdvicesAndAdvisorsForBean(beanClass, beanName, targetSource);
  } else {
    return DO_NOT_PROXY;
  }
}

60 15 .

, -

+1

, , , Time Time Weaving, , . , Compile Time Weaving. , spring ( 6, 8) AspectJ (http://www.eclipse.org/aspectj/docs.php)

AspectJ :

  • <aop:aspectj-autoproxy/> .
  • aspectJ . AspectJ ant, Codehaus maven. , .

Maven:

<plugin>
     <groupId>org.codehaus.mojo</groupId>
     <artifactId>aspectj-maven-plugin</artifactId>
     <version>1.3</version>
     <configuration>
     <verbose>true</verbose>
      <source>1.6</source>
      <target>1.6</target>
      <complianceLevel>1.6</complianceLevel>
      <showWeaveInfo>true</showWeaveInfo>
      <aspectLibraries>
        <aspectLibrary>
                                <groupId>org.springframework</groupId>
                                <artifactId>spring-aspects</artifactId>
                            </aspectLibrary>
                        </aspectLibraries>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>compile</goal>   
                            </goals>
                        </execution>
                    </executions>
                </plugin>

Ant

 <taskdef
            resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties">
            <classpath>
                <pathelement location="${lib.dir}/AspectJ_1.6.8/aspectjtools.jar"/>
            </classpath>
        </taskdef>

  <iajc aspectPath="${file.reference.spring-aspects.jar}; ${build.classes.dir}/path/to/custom/aspects"
              classpath="${lib.dir}/AspectJ_1.6.8/aspectjrt.jar; ${javac.classpath}"
              inpath="${build.classes.dir}"
              destDir="${build.classes.dir}"
              showWeaveInfo="true" />
+5

-, , -singleton beans. , Spring 3.1: https://jira.springsource.org/browse/SPR-7328

+2

, situtation, Spring empolying CachingBeanFactory.

beans, , , .

+1

? , .

, , , vms, SOA-. , , ..

, 3/4 , ( beans). , ​​ , - , .

, , - , factory .

+1

, jdk1.7 jdk1.6. jdk1.7 " Spring root WebApplicationContext" 30 . , , 10 .

0

All Articles