spring boot连接数据库时报错无法启动

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring boot连接数据库时报错无法启动相关的知识,希望对你有一定的参考价值。

2017-05-02 21:32:45.689 WARN 8576 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-05-02 21:32:45.894 ERROR 8576 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration required a bean of type 'javax.sql.DataSource' that could not be found.
- Bean method 'dataSource' not loaded because @ConditionalOnClass did not find required class 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType'
- Bean method 'dataSource' not loaded because @ConditionalOnClass did not find required class 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType'

Action:

Consider revisiting the conditions above or defining a bean of type 'javax.sql.DataSource' in your configuration.

pom.xml部分内容为下:

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

应该是你把pom文件里的tomcat给exclude了,在使用内置tomcat的时候,不要注释掉。

参考技术A @SpringBootApplication(exclude = DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class)

@SpringBootApplication这个是在springboot初始化的时候,创建的那个主类,在main方法上生命的,加入exclude = DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class就好了;意思是不让关于数据源的配置进行自动配置
参考技术B 你的datasource指定的什么?看你的application.properties或者application.yml

Consider revisiting the conditions above or defining a bean of type 'javax.sql.DataSource' in your configuration. 说的很明确了,
参考技术C 配置文件夹的问题

WDCP打开网页时报错:无法连接mysql,请检查mysql是否已启动及用户密码是否配置正确

今天公司很久以前的一台WDCP集成的Web服务出现了问题,打开网页显示“无法连接mysql,请检查mysql是否已启动及用户密码是否配置正确”

????技术分享图片

?????????????????(上图为服务器故障时Web访问报错信息)

????

????在网上找了三个小时的资料,找到了很多遇到该问题的朋友,并且只要是数据库连接不正常的或者数据库无法正常启动的,全都会报这个错误,下面是我的解决方法:


1、检查服务运行状态

[[email protected] etc]# service mysqld status

?mysql is not running.

#mysql服务并未运行


[[email protected] etc]# service mysqld restart

?ERROR! MySQL manager or server PID file could not be found!

Starting MySQL. ERROR! Manager of pid-file quit without updating file.

#试图重启服务,结果报错


[[email protected] etc]# cat /www/wdlinux/mysql-5.1.69/var/WDCP.err

查看WDCP的错误日志


? ? 171209 16:10:02 mysqld_safe mysqld from pid file /www/wdlinux/mysql-5.1.69/var/WDCP.pid ended

????171209 16:12:25 mysqld_safe Starting mysqld daemon with databases from /www/wdlinux/mysql-5.1.69/var

????171209 16:12:25 [ERROR] /www/wdlinux/mysql-5.1.69/libexec/mysqld: unknown variable ‘innodb_additional_mem_pool_size=16M

????171209 16:12:25 [ERROR] Aborting

????#从日志看为止的innodb我觉定把innodb的选项注释掉看一下,结果重启服务报了一个新的错误。


????171209 16:10:02 mysqld_safe mysqld from pid file /www/wdlinux/mysql-5.1.69/var/WDCP.pid ended

????171209 16:12:25 mysqld_safe Starting mysqld daemon with databases from /www/wdlinux/mysql-5.1.69/var

????171209 16:12:25 [ERROR] /www/wdlinux/mysql-5.1.69/libexec/mysqld: unknown variable ‘innodb_additional_mem_pool_size=16M‘

????171209 16:12:25 [ERROR] Aborting

????

????171209 16:12:25 [Note] /www/wdlinux/mysql-5.1.69/libexec/mysqld: Shutdown complete

????

????171209 16:12:25 mysqld_safe mysqld from pid file /www/wdlinux/mysql-5.1.69/var/WDCP.pid ended

????171209 16:13:32 mysqld_safe Starting mysqld daemon with databases from /www/wdlinux/mysql-5.1.69/var

????171209 16:13:32 [ERROR] /www/wdlinux/mysql-5.1.69/libexec/mysqld: unknown variable ‘innodb_buffer_pool_size=2G

????171209 16:13:32 [ERROR] Aborting

????#还是和innodb有关系,决定吧所有的innodb都注销掉!!!? ??


????171209 16:13:32 [Note] /www/wdlinux/mysql-5.1.69/libexec/mysqld: Shutdown complete

????

????171209 16:13:32 mysqld_safe mysqld from pid file /www/wdlinux/mysql-5.1.69/var/WDCP.pid ended

????171209 16:14:34 mysqld_safe Starting mysqld daemon with databases from /www/wdlinux/mysql-5.1.69/var

????171209 16:14:35 [ERROR] /www/wdlinux/mysql-5.1.69/libexec/mysqld: unknown variable ‘innodb_buffer_pool_size=2G‘

????171209 16:14:35 [ERROR] Aborting

????

????171209 16:14:35 [Note] /www/wdlinux/mysql-5.1.69/libexec/mysqld: Shutdown complete

????

????171209 16:14:35 mysqld_safe mysqld from pid file /www/wdlinux/mysql-5.1.69/var/WDCP.pid ended


? ? #在/www/wdlinux/etc/my.cnf有关innodb的选项全部注释掉

????#innodb_buffer_pool_size = 2G

????#innodb_data_file_path = ibdata1:10M:autoextend

????#innodb_file_io_threads = 4

????#innodb_thread_concurrency = 16

????#innodb_flush_log_at_trx_commit = 1

????#innodb_log_buffer_size = 8M

????#innodb_log_file_size = 256M

????#innodb_log_files_in_group = 3

????#innodb_max_dirty_pages_pct = 90

????#innodb_lock_wait_timeout = 120


????启动mysql服务进行测试:

????

????[[email protected] ~]# service mysqld start

????Starting MySQL. SUCCESS!

? ? #mysql启动成功


????具体原因暂时还没找到,主要是因为这不是主要的业务系统,以及该系统是前期开发人员搭建的,所以存在一些问题,此文档仅作为简单记录,查出具体问题后会整理详细文档。

以上是关于spring boot连接数据库时报错无法启动的主要内容,如果未能解决你的问题,请参考以下文章

小飞鱼通达二开 致远OA启动时报错“无法初始化数据库连接池,系统无法启动”的问题处理(图文)

小飞鱼通达二开 致远OA启动时报错“无法初始化数据库连接池,系统无法启动”的问题处理(图文)

Spring Boot连接DB2查询结果时报错“java.lang.AbstractMethodError: com.ibm.db2.jcc.t4.b.isValid(I)Z”的解决办法

启动spring boot项目时报错:java.lang.ClassNotFoundException: javax.servlet.Filter

spring boot 不连接数据库启动

springMVC 注解 启动时报错