mardi 24 mars 2015

exponentially increasing startup time (Spring initialization) on every added DAO interface

During startup, Spring warn-logging shows errors on creating e.g.

"bean with name 'userRepositoryInterface' ... Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required"

During the next few minutes this is repeated many times for each RepositoryInterface, but in the end the the problem is solved and the application works ok. But the startup time is unacceptable. Besides, when I added a new RepositoryInterface, the startup time expanded to 20 minutes until the server (weblogic 12c) ran out of memory.

The implementing classes of these RepositoryInterfaces are made by Spring/Mybatis (spring 4.1.3, mybatis 3.2.8 and mybatis-spring 1.2.2) that scans (xml) mapper-files to do this.

The repository (DAO) interfaces are autowired in the service-classes calling them, e.g.



@Autowired
private UserRepositoryInterface repository;


The repository interfaces are anotated with @Repository

I have a @Configuration and @MapperScan annotated PersistenceConfigurer that contains two @Bean methods:



  • DataSource dataSource()

  • SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource)


The dataSource and sqlSessionFactory are not called until the end of the startup process, that seems to be the problem.

I tried to change that by adding @Order(0) to the PersistenceConfigurer, but this had no effect. Moving the two Beans to other Configuration classes also had no positive effect.

For Spring I use Java configuration, no xml.


Aucun commentaire:

Enregistrer un commentaire