Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to disable spring boot HibernateJpaAutoConfiguration

i have an spring boot Project A that depend to project B. project B have some .hbm.xml resources. in the project A for change hibernate configuration i add DatabaseConfiguration @Configuration for change sessionFactory

@Bean
public LocalSessionFactoryBean sessionFactory() {
    LocalSessionFactoryBean sessionFactoryBean = new  LocalSessionFactoryBean();
    sessionFactoryBean.setDataSource(dataSource);
    sessionFactoryBean.setMappingLocations("classpath*:hibernate/**/*.hbm.xml");
    Properties hibernateProperties = new Properties();
    hibernateProperties.put("hibernate.dialect", HIBERNATE_DIALECT);
    hibernateProperties.put("hibernate.show_sql", HIBERNATE_SHOW_SQL);
    sessionFactoryBean.setHibernateProperties(hibernateProperties);

    return sessionFactoryBean;
}

build.gradle have this dependency HibernateJpaAutoConfiguration run

compile 'org.springframework.boot:spring-boot-starter-data-jpa'

when i run application in gradle bootRun or maven spring-boot:run application start and ok but when i run in java -jar i get exception

  caused by: org.springframework.beans.factory.BeanCreationException: 
  Error creating bean with name 'entityManagerFactory' defined in class path 
 resource    [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: 
 Invocation of init method failed; nested exception is org.hibernate.MappingException: 
An association from the table core_organization_Structure refers to an unmapped class: org.roshan.framework.domain.security.User

i dont know why HibernateJpaAutoConfiguration start ??? after that i change Application.java to like this for exclude that but again not work .when i copy hbm to projectA .project A run and ok (with java -jar)

@SpringBootApplication(exclude = {HibernateJpaAutoConfiguration.class })

update

after search and test ,i found problem and solve that .cause of problem was using hibernate-entitymanager dependency in project.spring boot actuator detect this and auto config entity manager .after remove this dependency disable HibernateJpaAutoConfiguration work correct :D

like image 399
ali akbar azizkhani Avatar asked May 29 '16 18:05

ali akbar azizkhani


2 Answers

Try this to disable data source auto configuration:

import org.springframework.boot.autoconfigure.*;
import org.springframework.boot.autoconfigure.jdbc.*;
import org.springframework.context.annotation.*;

@Configuration
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class MyConfiguration {
}
like image 60
ACV Avatar answered Sep 21 '22 18:09

ACV


after search and test ,i found problem ,cause of problem was using hibernate-entitymanager dependency in project.spring boot actuator detect this and auto config entity manager .after remove this dependency disable HibernateJpaAutoConfiguration work correct :D

like image 41
ali akbar azizkhani Avatar answered Sep 24 '22 18:09

ali akbar azizkhani