Spring boot Невозможно собрать Hibernate SessionFactory не показывает ошибку - PullRequest
0 голосов
/ 29 мая 2019

В приложении весенней загрузки + hibernate внесены некоторые изменения в базу данных и JPA, однако somethign кажется неэффективным, поскольку выдает ошибку при создании фабрики сеансов hibernate.

Но журналы не показывают, что не так.

Это ошибка журнала:

2019-05-29 15:39:19.166  WARN 8588 --- [ost-startStop-1] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'beansConfiguration': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [x/x/guias/config/JpaConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.persistence.EntityManagerFactory]: Factory method 'entityManagerFactory' threw exception; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: guiasUnitName] Unable to build Hibernate SessionFactory

Иногда это исправляет, обнаруживает ошибку, но должно сообщить, где происходит сбой hibernate.

это зависимости pom:

<dependencies>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.15</version>
    </dependency>

    <dependency>
        <groupId>org.omnifaces</groupId>
        <artifactId>omnifaces</artifactId>
        <version>1.5</version>
    </dependency>

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>21.0</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-cache</artifactId>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
    </dependency>

    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.2.0</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>facelets-taglib-jsf20-spring-3</artifactId>
        <version>0.5</version>
    </dependency>
    <!-- <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-taglibs</artifactId> 
        <version>5.0.3.RELEASE</version> </dependency> -->
    <!-- <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-taglibs</artifactId> 
        </dependency> -->

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-cas</artifactId>
    </dependency>

    <dependency>
        <groupId>org.jasig.cas.client</groupId>
        <artifactId>cas-client-support-saml</artifactId>
        <version>3.5.0</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <!-- Eliminado en 03/05/2019 por problema con dependencias anteriores 
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>-->

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.2.5</version>
    </dependency>

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.2.5</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/jstl/jstl -->
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.0.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-websocket</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>6.2</version>
    </dependency>

    <dependency>
        <groupId>net.bootsfaces</groupId>
        <artifactId>bootsfaces</artifactId>
        <version>1.2.0</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-configuration-processor</artifactId>
        <optional>true</optional>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
    </dependency>
    <!-- https://mvnrepository.com/artifact/net.sf.jasperreports/jasperreports -->
    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>6.8.0</version>
    </dependency>

</dependencies>

EDIT:

Файл конфигурации Jpa:

@Configuration
public class JpaConfig {

    @Autowired
    private DataSource guiasDataSource;

    @Autowired
    private Environment env;

    @Bean(name = "entityManager")
    public EntityManager entityManager() {
        return entityManagerFactory().createEntityManager();
    }

    @Bean(name = "entityManagerFactory")
    public EntityManagerFactory entityManagerFactory() {
        LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
        emf.setDataSource(guiasDataSource);
        emf.setJpaProperties(additionalJpaProperties());
        HibernateJpaVendorAdapter vendor = new HibernateJpaVendorAdapter();


        //vendor.setGenerateDdl(false);
        emf.setJpaVendorAdapter(vendor);
        emf.setPackagesToScan("x.x.guias");
        emf.setPersistenceUnitName("guiasUnitName");
        emf.afterPropertiesSet();
        return emf.getObject();
    }

    @Bean(name = "transactionManager")
    @Primary
    public PlatformTransactionManager transactionManager() {
        JpaTransactionManager tm = new JpaTransactionManager();
        tm.setEntityManagerFactory(entityManagerFactory());
        return tm;
    }

    private Properties additionalJpaProperties() {
        Properties properties = new Properties();


        properties.setProperty("hibernate.hbm2ddl.auto", "validate");

        properties.setProperty("hibernate.enable_lazy_load_no_trans",env.getProperty("hibernate.enable_lazy_load_no_trans"));
        properties.setProperty("show_sql", env.getProperty("show_sql"));
        properties.setProperty("format_sql", env.getProperty("format_sql"));
        return properties;
    }
}

Конфигурация источника данных:

@Configuration
public class DataSourceConfig {
    @Bean
    public DataSource evisadoDatasourceJndi() {
        JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
        return dataSourceLookup.getDataSource("jdbc/GuiasDS");
    }
}

JNDI-конфигурация:

<Resource name="jdbc/GuiasDS" auth="Container"
    type="javax.sql.DataSource"
    driverClassName="oracle.jdbc.driver.OracleDriver"
    url="jdbc:oracle:thin:@1.1.1.1:1111:YYYY" username="USER"
    password="XXX"
    maxActive="377"
    initialSize="5"
    accessToUnderlyingConnectionAllowed="true"
    maxWait="-1"
    removeAbandoned="true"
    removeAbandonedTimeout="55"
    singleton="false" />

application.properties:

server.servlet.contextPath=/guias

##################### Logging ##################
logging.level.x.x=DEBUG
logging.level.org.springframework=INFO
logging.level.org.springframework.security=debug
logging.level=TRACE

############################ DATASOURCE LOCAL x############################
hibernate.hbm2ddl.auto = validate

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
###############################################################################

management.endpoints.web.exposure.include=beans, info, metrics, loggers, heapdump, sessions, configprops, env, health

#App
##hibernate properties
show_sql = true
format_sql = true

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE

РЕДАКТИРОВАТЬ: 30/05/2019

Я решил это, используя проект без пружинной загрузки, поэтому проект без пружинной загрузки указывает, где таблица и сущность неверны. но весной загрузочный номер.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...