【错误解决】springBoot启动报错:Error starting ApplicationContext. To display the auto-configuration report re-

【错误解决】springBoot启动报错:Error starting ApplicationContext. To display the auto-configuration report re-run your application with ‘debug’ enabled.

错误信息:
Error starting ApplicationContext. To display the auto-configuration report re-run your application with ‘debug’ enabled.
Cannot determine embedded database driver class for database type NONE

Action:

If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).

网上搜索一大堆解决方案是:
springboot启动时会自动注入数据源和配置jpa
在@SpringBootApplication中排除其注入
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})

首先应该搞明白上面这句话是什么意思;启动的时候会自动注入数据源

因为很多新手都是直接copy别人的配置文件,
在配置文件中是这么写的
很多人在配置文件application.properties是这么写的:
spring.druid.url=jdbc:mysql://127.0.0.1:3306/xxx?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
spring.druid.username=root
spring.druid.password=xxxxx
spring.druid.maxActive=20
spring.druid.minIdle=3
spring.druid.maxWait=10000
spring.druid.validationQuery=SELECT ‘x’
spring.druid.timeBetweenEvictionRunsMillis=60000
spring.druid.minEvictableIdleTimeMillis=300000
spring.druid.borrowConnectionTimeout=30000

需要加上下面代码:
import java.sql.SQLException;

import javax.sql.DataSource;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.alibaba.druid.filter.Filter;
import com.alibaba.druid.filter.stat.StatFilter;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.http.StatViewServlet;
import com.google.common.collect.Lists;

@Configuration
public class DruidConfig {

@ConfigurationProperties(prefix="spring.druid")
@Bean(initMethod="init",destroyMethod="close")
public DataSource dataSource(Filter statFilter) throws SQLException{
	DruidDataSource dataSource = new DruidDataSource();
	dataSource.setProxyFilters(Lists.newArrayList(statFilter()));
	return dataSource;
}

@Bean
public Filter statFilter(){
	StatFilter filter = new StatFilter();
	filter.setSlowSqlMillis(5000);
	filter.setLogSlowSql(true);
	filter.setMergeSql(true);
	return filter;
}


@Bean
public ServletRegistrationBean servletRegistrationBean(){
	return new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
}

}

你可能感兴趣的:(报错信息)