在centos tomcat上运行Spring Boot应用程序出错

Posted

技术标签:

【中文标题】在centos tomcat上运行Spring Boot应用程序出错【英文标题】:Error on Running Spring Boot Application on centos tomcat 【发布时间】:2018-09-04 06:56:21 【问题描述】:

我的 Spring Boot 应用程序在 localhost 上运行良好,但是当我在 Centos 上运行它时出现错误。这是页面上显示的错误。

根本原因

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.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. 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).
     ....

根本原因

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. 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).
org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
      ....

根本原因

org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. 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).
      ....

根本原因

org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. 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).
org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:247)
    ....

application.yml 文件

`# ===============================
 # = Hibernate datasource
 # ===============================
spring:
  datasource:
    driverClassName: com.mysql.jdbc.Driver
    url: jdbc:mysql://67.209.127.115:3306/blog
    username: shadab
    password: test

    # ===============================
    # = JPA configurations
    # ===============================
  jpa:
     show-sql: true
     hibernate:
        ddl-auto: update

database-platform: MYSQL
properties:
  hibernate.dialect: org.hibernate.dialect.MySQL5Dialect

pom.xml 我在 pom.xml 文件中包含了 mysql-connector,但它仍然不起作用。

   <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>

【问题讨论】:

我们可以查看您的 appllication.properties 文件吗? 我有一个 application.yml 文件 好的,可以分享一下吗 我已经添加了 【参考方案1】:

您的类路径中缺少 MySQL 依赖项。只需将其放入 Maven/Gradle 构建中即可:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>

【讨论】:

以上是关于在centos tomcat上运行Spring Boot应用程序出错的主要内容,如果未能解决你的问题,请参考以下文章

如何在CentOS上搭建 Struts2+Spring+Hibernate的运行环境

如何在端口 80 上运行 tomcat 8.5/删除 8080。tomcat 8.5.16,centos 7 最小安装,托管 24

在一个 Tomcat 上运行多个 Spring-boot 应用程序

Spring运行在tomcat上

怎么把struts2项目部署在Tomcat上,求步骤

在本地 tomcat 上运行的 Spring Boot 应用程序在 Elastic Beanstalk 上提供 404