我是 Spring Boot 的新手。我正在 java 1.8 编译器上使用 spring boot 2.2、hibernate 5 和 MySQL 构建一个 rest API。当我在我的 apache tomcat v8.0 服务器上运行我的 spring boot rest API 应用程序时,服务器启动并且应用程序运行并显示我的索引页面。在构建(全新安装)我的应用程序并尝试在服务器上运行它后,服务器拒绝启动并出现错误“本地主机上的服务器 Tomcat v8.0 服务器启动失败。”。请问,这可能是什么原因?
这是完整的错误:
Dec 12, 2019 8:42:12 AM org.apache.catalina.startup.VersionLoggerListener
log
INFO: Server version name: Apache Tomcat/9.0.27
Dec 12, 2019 8:42:12 AM org.apache.catalina.startup.VersionLoggerListener
log
INFO: Server built: Oct 7 2019 09:57:22 UTC
Dec 12, 2019 8:42:12 AM org.apache.catalina.startup.VersionLoggerListener
log
INFO: Server version number: 9.0.27.0
Dec 12, 2019 8:42:12 AM org.apache.catalina.startup.VersionLoggerListener
log
INFO: OS Name: Windows 10
Dec 12, 2019 8:42:12 AM org.apache.catalina.startup.VersionLoggerListener
log
INFO: OS Version: 10.0
Dec 12, 2019 8:42:12 AM org.apache.catalina.startup.VersionLoggerListener
log
INFO: Architecture: amd64
Dec 12, 2019 8:42:12 AM org.apache.catalina.startup.VersionLoggerListener
log
INFO: Java Home: C:\Program Files\Java\jdk1.8.0_171\jre
Dec 12, 2019 8:42:12 AM org.apache.catalina.startup.VersionLoggerListener
log
INFO: JVM Version: 1.8.0_171-b11
Dec 12, 2019 8:42:12 AM org.apache.catalina.startup.VersionLoggerListener
log
INFO: JVM Vendor: Oracle Corporation
Dec 12, 2019 8:42:12 AM org.apache.catalina.startup.VersionLoggerListener
log
INFO: CATALINA_BASE: C:\Users\Harry\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Dec 12, 2019 8:42:12 AM org.apache.catalina.startup.VersionLoggerListener
log
INFO: CATALINA_HOME: C:\Program Files (x86)\Apache Software
Foundation\Tomcat 9.0
Dec 12, 2019 8:42:12 AM org.apache.catalina.startup.VersionLoggerListener
log INFO: Command line argument: Dcatalina.base=C:\Users\Harry\workspace\.metadata\.plugins\org.eclipse.wst.ser
ver.core\tmp0
Dec 12, 2019 8:42:12 AM org.apache.catalina.startup.VersionLoggerListener
log
INFO: Command line argument: -Dcatalina.home=C:\Program Files (x86)\Apache
Software Foundation\Tomcat 9.0
Dec 12, 2019 8:42:12 AM org.apache.catalina.startup.VersionLoggerListener
log INFO: Command line argument: Dwtp.deploy=C:\Users\Harry\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
Dec 12, 2019 8:42:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\Program Files (x86)\Apache Software Foundation\Tomcat 9.0\endorsed
Dec 12, 2019 8:42:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
Dec 12, 2019 8:42:12 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path:
[C:\Program Files\Java\jdk1.8.0_171\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/ProgramFiles/Java/jdk1.8.0_171/bin/../jre/bin/server;C:/ProgramFiles/Java/jdk1.8.0_171/bin/../jre/bin;C:/ProgramFiles/Java/jdk1.8.0_171/bin/../jre/lib/amd64;C:\oraclexe\app\oracle\product\11.2.0\server\bin;C:\ProgramFiles\Java\jdk1.8.0_171\bin;C:\Program Files (x86)\CommonFiles\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\ProgramFiles\Microsoft VSCode\bin;C:\xampp\php;C:\ProgramData\ComposerSetup\bin;C:\WINDOWS\System32\penSSH\;C:\Program Files\nodejs\;C:\Users\Harry\workspace\apache-maven-3.6.2\bin;C:\Program Files\Microsoft VSCode\bin;C:\Users\Harry\AppData\Roaming\Composer\vendor\bin;C:\Users\Harry\appData\Local\Microsoft\WindowsApps;C:\Users\Harry\AppData\Roaming\npm;C:\Users\Harry\AppData\Local\Programs\Python\Python37-32;C:\Users\Harry\AppData\Local\Programs\Python\Python37-32\Scripts;;C:\Program Files (x86)\eclipse;;.]
Dec 12, 2019 8:42:13 AM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["http-nio-8083"]
Dec 12, 2019 8:42:13 AM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["ajp-nio-8012"]
Dec 12, 2019 8:42:13 AM org.apache.catalina.startup.Catalina load INFO: Server initialization in [1,929] milliseconds
Dec 12, 2019 8:42:13 AM org.apache.catalina.core.StandardService startInternal INFO: Starting service [Catalina]
Dec 12, 2019 8:42:13 AM org.apache.catalina.core.StandardEngine startInternal INFO: Starting Servlet engine: [Apache Tomcat/9.0.27]
Dec 12, 2019 8:42:27 AM org.apache.catalina.core.ApplicationContext log INFO: 2 Spring WebApplicationInitializers detected on classpath
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.2.RELEASE)
2019-12-12 08:42:30.969 INFO 22232 --- [main] c.a.e.SpringBootApplications: Starting SpringBootApplications v0.0.1-SNAPSHOT on Harry with PID 22232(C:\Users\Harry\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0 wtpwebapps\ecclesiamainframe\WEB-INF\classes started by Harry in C:\ProgramFiles (x86)\eclipse) 2019-12-12 08:42:30.993 INFO 22232 --- [main] c.a.e.SpringBootApplications : No active profile set, falling back to default profiles: default 2019-12-12 08:42:35.300 INFO 22232 --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPArepositories in DEFAULT mode.
2019-12-12 08:42:35.720 INFO 22232 ---[main].s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 349ms. Found 1 JPA repository interfaces.
2019-12-12 08:42:37.814 INFO 22232 --- [main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-12-12 08:42:38.008 INFO 22232 --- [main] o.a.c.c.C.[.[.[/ecclesiamainframe] : Initializing Spring embedded WebApplicationContext
2019-12-12 08:42:38.008 INFO 22232 --- [main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 6786 ms
2019-12-12 08:42:38.622 WARN 22232 --- [main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': 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$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2019-12-12 08:42:38.664 INFO 22232 --- [main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-12-12 08:42:38.682 ERROR 22232 --- [main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
这是我的 pox.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion>
<groupId>com.app</groupId>
<artifactId>ecclesiamainframe</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>ecclesiamainframe Maven Webapp</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- exclude tomcat jdbc connection pool, use HikariCP -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
<!-- exclude tomcat-jdbc , spring boot will use use HikariCP automatically -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-hikaricp</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>providedRuntime</scope>
</dependency>
<!--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>hibernate-types-52</artifactId>
<version>2.8.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<finalName>ecclesiamainframe</finalName>
</build>
</project>
这是我的 Application.properties
#Database connection Properties
spring.datasource.url=jdbc:mysql://localhost:3306/ecclesia_mainframe_db
#?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&characterEncoding=UTF-8&autoReconnect=yes
#database credential
spring.datasource.username = devteam
spring.datasource.password = softmysql2019
server.port=8090
spring.datasource.driver-class-name = com.mysql.cj.jdbc.Driver
#The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
#spring.datasource.hikari.connection-timeout=200000
#spring.datasource.hikari.maximum-pool-size=3000
#Turn Statistics on and log SQL stmts
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
#If want to see very extensive logging
spring.jpa.properties.hibernate.generate_statistics=true
logging.level.org.hibernate.type=trace
logging.level.org.hibernate.stat=debug
#Schema will be created using schema.sql and data.sql files
#spring.jpa.hibernate.ddl-auto=none
#Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto=update
我已经在堆栈上尝试了很多解决方案,但错误仍然存在。