Вот мой класс конфигурации db! Это отлично работает для весенней загрузки 1.5.14, но не для 2.1.4. У меня есть репозиторий Jpa и класс dao, поэтому LocalSessionFactoryBean
выставляет EntityMangerFactory
bean в весенней загрузке 1.5.14, но на 2.1.4! Я получаю следующие ошибки:
Cannot create inner bean '(inner bean)#624a24f6' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#624a24f6': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
@Bean
@Primary
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setUrl(env.getProperty("live.datasource.url"));
dataSource.setDriverClassName(env.getProperty("live.datasource.driver-class-name"));
dataSource.setUsername(env.getProperty("live.datasource.username"));
dataSource.setPassword(env.getProperty("live.datasource.password"));
return dataSource;
}
@Bean
@Primary
public LocalSessionFactoryBean sessionFactory(ConfigurableListableBeanFactory beanFactory) {
LocalSessionFactoryBean localSessionFactoryBean = new LocalSessionFactoryBean();
localSessionFactoryBean.setDataSource(this.DataSource());
Properties hibernateProperties = new Properties();
hibernateProperties.put("hibernate.dialect", this.env.getProperty("live.datasource.jpa.properties.hibernate.dialect"));
hibernateProperties.put("hibernate.show_sql", this.env.getProperty("live.datasource.jpa.properties.hibernate.show_sql"));
localSessionFactoryBean.setHibernateProperties(hibernateProperties);
return localSessionFactoryBean;
}
@Bean("TransactionManager")
@Primary
public PlatformTransactionManager TransactionManager() {
HibernateTransactionManager hibernateTransactionManager = new HibernateTransactionManager();
hibernateTransactionManager.setDataSource(this.DataSource());
hibernateTransactionManager.setSessionFactory(this.sessionFactory().getObject());
return hibernateTransactionManager;
}