Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0 M2
    • Fix Version/s: 1.2 M1
    • Component/s: Core

      Description

      Please support repositories scanning using java config, equivalent to XML jpa:repositories namespace, with same capabilities, like option to specify/reference specific EntityManagerFactory and PlatformTransactionManager.

      E.g. create @RepositoriesScan, similar to @org.springframework.context.annotation.ComponentScan from Spring 3.1, and supporting logic

        Issue Links

          Activity

          Hide
          Mikael Gueck added a comment -

          Meanwhile, could you provide a description of the recommended way of integrating Spring Data JPA into a programmatically configured Spring (MVC) application?

          When using the naive standalone configuration in the documentation, the resulting DAO doesn't appear to save or flush entities. I'm happy to debug the problem further, but I'd like to be certain that I'm not making an elementary configuration mistake, before committing the time.

          Show
          Mikael Gueck added a comment - Meanwhile, could you provide a description of the recommended way of integrating Spring Data JPA into a programmatically configured Spring (MVC) application? When using the naive standalone configuration in the documentation, the resulting DAO doesn't appear to save or flush entities. I'm happy to debug the problem further, but I'd like to be certain that I'm not making an elementary configuration mistake, before committing the time.
          Hide
          Oliver Gierke added a comment -

          Hi, I've just verified the following to work:

          @Configuration
          public MyConfiguration {
          
            @Autowired
            EntityManager entityManager;
            @Autowired
            BeanFactory beanFactory;
          
            @Bean
            public MyRepository myRepository() {
            
              JpaRepositoryFactoryBean<MyRepository, Person, Long> factory = new JpaRepositoryFactoryBean<MyRepository, Person, Long>();
              factory.setBeanFactory(beanFactory);
              factory.setEntityManager(entityManager);
              factory.setRepositoryInterface(MyRepository.class);
              factory.afterPropertiesSet();
              
              return factory.getObject();
            }
          }
          

          See the just commited test case (slightly more complicated) for an executable example.

          Show
          Oliver Gierke added a comment - Hi, I've just verified the following to work: @Configuration public MyConfiguration { @Autowired EntityManager entityManager; @Autowired BeanFactory beanFactory; @Bean public MyRepository myRepository() { JpaRepositoryFactoryBean<MyRepository, Person, Long > factory = new JpaRepositoryFactoryBean<MyRepository, Person, Long >(); factory.setBeanFactory(beanFactory); factory.setEntityManager(entityManager); factory.setRepositoryInterface(MyRepository.class); factory.afterPropertiesSet(); return factory.getObject(); } } See the just commited test case (slightly more complicated) for an executable example.
          Hide
          William Gorder added a comment -

          Hey Oliver with this approach you would have to define all your repositories. Is there away to still make use of the package scanning like we would have in the XML configuration?

          Show
          William Gorder added a comment - Hey Oliver with this approach you would have to define all your repositories. Is there away to still make use of the package scanning like we would have in the XML configuration?
          Hide
          Oliver Gierke added a comment -

          Nope, the @Bean approach only allows to register one bean per method so we will go down the @Enable… to mimic the behaviour of <jpa:repositories /> in the future. As most of the functionality is in Spring Data Commons feel free to track progress of DATACMNS-47.

          Show
          Oliver Gierke added a comment - Nope, the @Bean approach only allows to register one bean per method so we will go down the @Enable… to mimic the behaviour of <jpa:repositories /> in the future. As most of the functionality is in Spring Data Commons feel free to track progress of DATACMNS-47 .

            People

            • Assignee:
              Oliver Gierke
              Reporter:
              Stevo Slavić
            • Votes:
              29 Vote for this issue
              Watchers:
              26 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: