Announcement Announcement Module
Collapse

JavaConfig forum decommissioned in favor of Core Container

As described at

http://static.springsource.org/sprin...fig/README.TXT

key features of the Spring JavaConfig project have been migrated into the core Spring Framework as of version 3.0.

Please see the Spring 3.0 documentation on @Configuration and @Bean support:

http://static.springsource.org/sprin...tml#beans-java

For any questions related to @Configuration classes and @Bean methods in Spring 3.0, please post in the dedicated 'Core Container' forum at

http://forum.springsource.org/forumdisplay.php?f=26
See more
See less
@ComponentScan and Lazy-initialization of beans ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @ComponentScan and Lazy-initialization of beans ?

    Hi,

    I'm converting my spring configuration to use JavaConfig and i've a problem with component-scan.

    Before using JavaConfig, i used a ClassPathBeanDefinitionScanner. I need lazy-init on the beans, so i made :

    Code:
    BeanDefinitionDefaults defaults = new BeanDefinitionDefaults();
    defaults.setLazyInit(true);
    scanner.setBeanDefinitionDefaults(defaults);
    But now, i didn't found how to do that in JavaConfig. I thougt that i can just set the defaultLazy option of the @Configuration, but it didn't work.

    Actually, i use the context like that :

    Code:
    JavaConfigApplicationContext configApplicationContext =
                    new JavaConfigApplicationContext(SpringConfiguration.class, FilmsSpringConfiguration.class, PrimaryConfiguration.class);
    And my three configurations looks like that :

    Code:
    @ComponentScan("org.jtheque.core.managers.persistence.context")
    @Configuration(defaultLazy = Lazy.TRUE)
    @AnnotationDrivenConfig
    @AnnotationDrivenTx(transactionManager = "txManager")
    public class SpringConfiguration extends ConfigurationSupport{
        @Bean
        public EntityManagerFactory entityManagerFactory(){
            EntityManagerFactoryBean factory = new EntityManagerFactoryBean();
    
            return (EntityManagerFactory)getObject(factory);
        }
    
        @Bean
        public JpaTransactionManager txManager(){
            return new JpaTransactionManager(entityManagerFactory());
        }
    
        @Bean
        public ResourceBundleMessageSource messageSource(){
            return new ResourceBundleMessageSource();
        }
    }
    Code:
    @Configuration(defaultLazy = Lazy.TRUE)
    @ComponentScan(value = {
            "org.jtheque.films.services.impl",
            "org.jtheque.films.persistence.dao.impl",
            "org.jtheque.films.view.impl.frames",
            "org.jtheque.films.view.impl.panels",
            "org.jtheque.films.controllers.impl"}
    )
    public class FilmsSpringConfiguration {
        
    }
    Code:
    @Configuration(defaultLazy = Lazy.TRUE)
    @ComponentScan(value = {
            "org.jtheque.primary.dao.impl",
            "org.jtheque.primary.services.impl",
            "org.jtheque.primary.view.frames",
            "org.jtheque.primary.controller"}
    )
    public class PrimarySpringConfiguration {
    }
    Is there a way to enable the lazy-initialization on my scanned components ?

    Thank you very much and thanks for this very good project

  • #2
    Hi @wichtounet,

    I'm sorry to report that, even though the 'defaultLazy' attribute is there on @Configuration, it was never properly supported. There is an existing bug on this matter, and you can read my response there:

    http://jira.springframework.org/browse/SJC-263

    Best,

    - Chris

    Comment


    • #3
      Originally posted by Chris Beams View Post
      Hi @wichtounet,

      I'm sorry to report that, even though the 'defaultLazy' attribute is there on @Configuration, it was never properly supported. There is an existing bug on this matter, and you can read my response there:

      http://jira.springframework.org/browse/SJC-263

      Best,

      - Chris
      Hi,

      Thank you for responding.

      That's not a good news for me

      I need the lazy-init on my scanned beans.

      Is there a way to mix a ClassPathBeanDefinitionScanner and a JavaConfigApplicationContext ?

      Comment


      • #4
        Or another way : Is that possible to define component-scan with defaults lazy in different XML imported with @ImportXML ?

        This is not elegant, but if it works, i can use that waiting of an issue to JavaConfig ComponentScan.

        Comment

        Working...
        X