spring-boot: Parameter 0 of constructor in org.springframework.data.jpa.repository.support.DefaultJpaContext required a bean of type 'java.util.Set' that could not be found.

After migrating to SpringBoot 1.4.1, Spring Data Hopper-SR3 has updated and all projects are throwing the exception:

If I reduce the dependency to Hopper-SR2 it works fine again.

***************************
APPLICATION FAILED TO START
***************************
Description:

Parameter 0 of constructor in org.springframework.data.jpa.repository.support.DefaultJpaContext required a bean of type 'java.util.Set' that could not be found.

Action:
Consider defining a bean of type 'java.util.Set' in your configuration.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 17 (6 by maintainers)

Most upvoted comments

The only solution that I found is to manually exclude JpaRepositoriesAutoConfiguration from spring boot and manually configure it:

@SpringBootApplication(scanBasePackages = {"test"} , exclude = JpaRepositoriesAutoConfiguration.class)
@EnableTransactionManagement
public class App extends SpringBootServletInitializer {
        public static void main(String[] args) {
            SpringApplication.run(App.class, args);
        }

        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(App.class);
        }
}

Thank you Demonian, all good works if you configure next configuration DB class code:

@Configuration
public class DatabaseConfig {

    @Autowired
    private Environment env;


    @Bean
    public LocalSessionFactoryBean sessionFactory(DataSource dataSource) {
        LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
        sessionFactory.setDataSource(dataSource);
        sessionFactory.setPackagesToScan("{path to your database classes}");
        sessionFactory.setHibernateProperties(hibernateProperties());
        return sessionFactory;
    }

    public Properties hibernateProperties() {
        return new Properties() {
            {
                setProperty("hibernate.hbm2ddl.auto", env.getProperty("datasource.ddl-auto"));
                setProperty("hibernate.dialect", env.getProperty("datasource.hibernate.dialect"));
                setProperty("hibernate.show_sql", env.getProperty("datasource.show-sql"));
                setProperty("hibernate.format_sql", env.getProperty("datasource.format-sql"));
            }
        };
    }

    @Bean
    public HibernateTransactionManager transactionManager(SessionFactory sessionFactory) {
        return new HibernateTransactionManager(sessionFactory);
    }

    @Bean
    public HibernateTemplate hibernateTemplate(SessionFactory sessionFactory) {
        return new HibernateTemplate(sessionFactory);
    }

}

And in YAML file write next data, example for postgres:

spring:
  datasource:
    url: jdbc:postgresql://{URL to postgres}:{postgres port}/{database name}
    username: {postgres username}
    password: {postgres password}
    driver-class-name: org.postgresql.Driver


logging:
  level:
    org.springframework: INFO
#    org.hibernate: DEBUG
    {main package path}: INFO

datasource:
  hibernate.dialect: org.hibernate.dialect.PostgreSQL95Dialect
  ddl-auto : none
  show-sql : false
  format-sql : true

And all good works!!! Thanks all. Regards.

The solution @SpringBootApplication(scanBasePackages = {"boot.registration"} , exclude = JpaRepositoriesAutoConfiguration.class) worked for me