admin管理员组文章数量:1571330
报错信息
Description:
Reason: Failed to determine a suitable driver class
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).
06-Aug-2020 00:36:05.740 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/ExcelDemo]]
at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:970)
at org.apache.catalina.startup.HostConfig
D
e
p
l
o
y
W
a
r
.
r
u
n
(
H
o
s
t
C
o
n
f
i
g
.
j
a
v
a
:
1840
)
a
t
j
a
v
a
.
u
t
i
l
.
c
o
n
c
u
r
r
e
n
t
.
E
x
e
c
u
t
o
r
s
DeployWar.run(HostConfig.java:1840) at java.util.concurrent.Executors
DeployWar.run(HostConfig.java:1840)atjava.util.concurrent.ExecutorsRunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor
W
o
r
k
e
r
.
r
u
n
(
T
h
r
e
a
d
P
o
o
l
E
x
e
c
u
t
o
r
.
j
a
v
a
:
624
)
a
t
j
a
v
a
.
l
a
n
g
.
T
h
r
e
a
d
.
r
u
n
(
T
h
r
e
a
d
.
j
a
v
a
:
748
)
C
a
u
s
e
d
b
y
:
o
r
g
.
s
p
r
i
n
g
f
r
a
m
e
w
o
r
k
.
b
e
a
n
s
.
f
a
c
t
o
r
y
.
B
e
a
n
C
r
e
a
t
i
o
n
E
x
c
e
p
t
i
o
n
:
E
r
r
o
r
c
r
e
a
t
i
n
g
b
e
a
n
w
i
t
h
n
a
m
e
′
d
a
t
a
S
o
u
r
c
e
′
d
e
f
i
n
e
d
i
n
c
l
a
s
s
p
a
t
h
r
e
s
o
u
r
c
e
[
o
r
g
/
s
p
r
i
n
g
f
r
a
m
e
w
o
r
k
/
b
o
o
t
/
a
u
t
o
c
o
n
f
i
g
u
r
e
/
j
d
b
c
/
D
a
t
a
S
o
u
r
c
e
C
o
n
f
i
g
u
r
a
t
i
o
n
Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration
Worker.run(ThreadPoolExecutor.java:624)atjava.lang.Thread.run(Thread.java:748)Causedby:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname′dataSource′definedinclasspathresource[org/springframework/boot/autoconfigure/jdbc/DataSourceConfigurationTomcat.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: Failed to determine a suitable driver class
解释
Failed to determine a suitable driver class
无法明确指定正确的驱动类(driver.class)
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
如果有数据库设置需要从指定配置文件中加载,需要调用该配置文件(目前没有活动的配置文件)
分析
报错的原因是因为导入的两个依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>-
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
这两个依赖的导入需要有他们支持的相关的配置文件web 、 mybatis。
解决
程序入口处:
@SpringBootApplication
public class DemoApplication {
修改为:
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class DemoApplication {
补充
springboot项目打包部署流程:
1、打成jar包。
1)修改pom.xml
首先在pom.xml文件中导入Springboot的maven依赖;
<!--将应用打包成一个可以执行的jar包-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
2)执行打包操作:Run maven——>package
3)在target目录下,就能看到项目名.jar文件了 。
4)找到对应的jar包路径下,java -jar 打包后的名字即可运行成功。
2、打成war包。
1)修改pom.xml
找到打包的标签,将里面的jar改成war
<packaging>war</packaging>
需要移除内置Tomcat的依赖:将原来我们用的spring-boot-starter-web 加入加上<exclusion>如下表示
<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>
2)修改启动类
//修改前
@SpringBootApplication
public class RecyclingApplication {
public static void main(String[] args) {
SpringApplication.run(RecyclingApplication.class, args);
}
}
//修改后
@SpringBootApplication
public class RecyclingApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(RecyclingApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(RecyclingApplication.class, args);
}
}
3)执行打包操作:Run maven——>install
4)在target目录下,就能看到项目名.war文件了 。
4)将.war文件放到服务器的webapps下就好了。
提示:maven项目打包的过程中,会将pom.xml中的依赖对应的jar包下载到WEB-INF的lib目录下。所以服务器上面并不需要maven环境。
本文标签: 报错服务器项目SpringBoot
版权声明:本文标题:springboot项目本地运行正常,部署服务器报错 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1727690103a1125767.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论