使用gradle依赖项启动Spring Boot应用程序时出错

时间:2015-10-09 06:58:57

标签: gradle spring-boot spring-data-jpa

获取此错误请帮助我

Exception in thread "main" 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.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:961)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:950)
        at com.omneagate.rest.RestApplication.main(RestApplication.java:223)
    Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
        at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:104)
        at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:71)
        at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:205)
        at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
        at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:852)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:845)
        at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844)
        at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
        at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)
        ... 15 more

我的application.properties文件

# datasource properties
spring.datasource.url=jdbc:mysql://localhost:3306/pds_00038_11092015
spring.datasource.username=dev
spring.datasource.password=dev123
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.testOnBorrow=true
spring.datasource.validationQuery=SELECT 1
spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
security.headers.cache=false
security.sessions=stateless
server.port=9094
#security.basic.enabled=false

# rabbit mqueue configurations
spring.rabbitmq.host=localhost
spring.rabbitmq.username=debendrap
spring.rabbitmq.password=debendrap
spring.rabbitmq.virtual-host=debendrap
queue.name=deb1
queue.concurrentuser=100
queue.maxconcurrent.user=512

# rabbit mqueue configurations
smstask.queue.name=pdssmstask
smstask.queue.concurrentuser=30
smstask.queue.maxconcurrent.user=100

# application configurations
stringdigester.iteration.count=1000
stringdigester.poolsize.count=16
stringdigester.saltsize=10

threadexecutor.core.poolsize=50
threadexecutor.max.poolsize=500
threadexecutor.queue.capacity=250

#sms expiry time
sms.expirytime=180 

#except sms url please do not change other properties
#sms service url
sms.service.url=http://localhost:8880/pdsmessagingwebservice/smsrequest/sendsms

#sms service username
sms.service.username=pd$smsuser

#sms service password
sms.service.password=p@$$word!

#bill item details in txn
txn.billitem.msg=%s(%s)Rs%s;

#****** Otp related properties *******#
#otp length
otp.length=7

#sms expiry time
#In seconds. Used for transactions
otp.expirytime=180

#sms expiry time
#In seconds. Used for activation
otp.activationreq.expiry=10080  

#****** Otp related properties*******#
#Do not change the algorithm
encryption.algorithm=PBEWITHSHA-256AND256BITAES-CBC-BC

ldap.service.url=http://localhost:9060/peopleldap/authenticate

#Open LDAP configuration
ldap.url=ldap://localhost
ldap.base=dc=cscpd,dc=in
ldap.user=cn=admin,dc=cscpd,dc=in
ldap.password=cscpdpds

#******* Elcot db compare service ****#
# possible values true or false
elcotdb.compareservice.enable=false
# Only number allowed
elcotdb.fixedthreadpool.size=10

---------------------------------------------------------------------------
my RestApplication.java file

package com.omneagate.rest;

import java.util.ArrayList;
import java.util.List;

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.jasypt.digest.PooledStringDigester;
import org.jasypt.digest.StringDigester;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.core.env.Environment;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.LdapContextSource;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.omneagate.rest.elcotcompare.ElcotCompareTask;
import com.omneagate.rest.security.FpsFilter;
import com.omneagate.rest.service.SmsTaskListener;
import com.omneagate.utilities.LdapTreeBuilder;

@Configuration  
@EnableAutoConfiguration
@ComponentScan
@EnableTransactionManagement
@ImportResource("classpath:security.xml" )
@EnableScheduling
// This class is the entry point of the application.
public class RestApplication {
    @Value("${queue.name}")
    String queueName;

    @Value("${queue.concurrentuser}")
    int concurrentUsers;

    @Value("${queue.maxconcurrent.user}")
    int maxConcurrentUsers;

    /** String digester properties */
    @Value("${stringdigester.poolsize.count}")
    int stringDigesterPoolSize;

    @Value("${stringdigester.iteration.count}")
    int stringDigesterIterations;

    @Value("${stringdigester.saltsize}")
    int stringDigesterSaltSize;

    /** Thread executor properties */
    @Value("${threadexecutor.core.poolsize}")
    int threadExecutorCoreSize;

    @Value("${threadexecutor.max.poolsize}")
    int threadPoolMaxSize;

    @Value("${threadexecutor.queue.capacity}")
    int threadPoolQueueCapacity;

    /** SMS Task queue configuration */
    @Value("${smstask.queue.name}")
    String smsTaskqueue;

    @Value("${smstask.queue.concurrentuser}")
    int smsTaskConcurrentUsers;

    @Value("${queue.maxconcurrent.user}")
    int smsTaskMaxConcurrentUser;

    @Bean
    MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }

    @Bean
    RabbitTemplate template(ConnectionFactory connectionFactory,
            MessageConverter converter) {
        RabbitTemplate template = new RabbitTemplate(connectionFactory);
        template.setMessageConverter(converter);
        return template;
    }

    @Bean
    SimpleMessageListenerContainer container(
            ConnectionFactory connectionFactory,
            MessageListenerAdapter listenerAdapter) {
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(
                connectionFactory);
        container.setQueueNames(queueName);
        container.setConcurrentConsumers(concurrentUsers);
        container.setMaxConcurrentConsumers(maxConcurrentUsers);
        container.setMessageListener(listenerAdapter);
        //container.setTaskExecutor(getAsyncExecutor());
        return container;
    }

    @Bean
    SmsTaskListener smsTaskListener(){
        return new SmsTaskListener();
    }

    @Bean
    SimpleMessageListenerContainer smsTaskContainer(
            ConnectionFactory connectionFactory,MessageConverter converter) {
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(
                connectionFactory);
        container.setQueueNames(smsTaskqueue);
        container.setConcurrentConsumers(smsTaskConcurrentUsers);
        container.setMaxConcurrentConsumers(smsTaskMaxConcurrentUser);
        container.setMessageListener(new MessageListenerAdapter(smsTaskListener(),converter));
        //container.setTaskExecutor(getAsyncExecutor());
        return container;
    }

    @Bean
    StringDigester PasswordHash() {
        final PooledStringDigester stringDigester = new PooledStringDigester();
        stringDigester.setAlgorithm("SHA-256");
        stringDigester.setIterations(stringDigesterIterations);
        stringDigester.setSaltSizeBytes(stringDigesterSaltSize);
        stringDigester.setPoolSize(stringDigesterPoolSize);
        stringDigester.initialize();
        return stringDigester; 
    }

    @Bean
    MessageListenerAdapter listenerAdapter(
            com.omneagate.rest.service.Listener listener,
            MessageConverter converter) {
        return new MessageListenerAdapter(listener, converter);
    }

    @Bean(name="threadexecutor")
    public ThreadPoolTaskExecutor getAsyncExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
            executor.setCorePoolSize(threadExecutorCoreSize);
            executor.setMaxPoolSize(threadPoolMaxSize);
            executor.setQueueCapacity(threadPoolQueueCapacity);
            executor.initialize();
            return executor;
    }

    @Bean
    Queue queue() {
        return new Queue(queueName, true);
    }

    @Bean
    Queue smsTaskqueue() {
        return new Queue(smsTaskqueue, true);
    }

    @Bean
    public FilterRegistrationBean authorizationFilter() {
        FilterRegistrationBean filterRegBean = new FilterRegistrationBean();
        filterRegBean.setFilter(new FpsFilter());
        List<String> urlPatterns = new ArrayList<String>();
        urlPatterns.add("/*");
        filterRegBean.setUrlPatterns(urlPatterns);
        return filterRegBean;
    }

    @Autowired
    Environment env;

    @Bean
    public LdapContextSource contextSource () {
        LdapContextSource contextSource= new LdapContextSource();
        contextSource.setUrl(env.getRequiredProperty("ldap.url"));
        contextSource.setBase(env.getRequiredProperty("ldap.base"));
        contextSource.setUserDn(env.getRequiredProperty("ldap.user"));
        contextSource.setPassword(env.getRequiredProperty("ldap.password"));
        return contextSource;
    }

    @Bean
    public LdapTreeBuilder ldapTreeBuilder(){
        return new LdapTreeBuilder(ldapTemplate());
    }

    @Bean
    public LdapTemplate ldapTemplate() {
        return new LdapTemplate(contextSource());        
    }

    @Bean
    public StandardPBEStringEncryptor getEncryptor() {
        return new StandardPBEStringEncryptor();        
    }

    @Bean
    public BouncyCastleProvider getCipherProvider() {
        return new BouncyCastleProvider();        
    }

    @Bean   
    public ElcotCompareTask elcotCompareTask() {
        return new ElcotCompareTask();        
    }

    public void scheduleElcotCompare(){
        new ElcotCompareTask();
    }

    public static void main(String[] args) {
        SpringApplication.run(RestApplication.class, args);
    }
}

1 个答案:

答案 0 :(得分:5)

尝试在application.properties文件中设置此属性:

spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect

(正确的方言取决于你的数据库)

JPA需要它能够生成正确的代码以与您的数据库进行交互。

如果没有帮助,请提供有关您的申请的更多信息。你是否重写了spring-boot的自动配置?您在gradle文件中使用了哪些依赖项?您是否包含spring-boot-starter-data-jpa和数据库连接器?