小菜鸟遇到的SpringBoot报错解决方案

Scroll Down
SringBoot报错:
java.lang.ClassNotFoundException: org.springframework.context.event.GenericApplicationListener

原因:GenericApplicationListener是从spring版本4.2中添加的。

解决方法:将spring版本升级到4.2并重新检查。

Canot determine embedded database driver class for database type NONE

原因:产生这个异常发现是 SpringBoot 启动时会自动注入数据源和配置 jpa
解决方法:

maven中添加jar

<!— jpa SpringBoot 启动时会自动注入数据源和配置 jpa —>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-></artifactId>
</dependency>

同时在启动类中加入以下代码:

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})

此代码的意思是:排除掉一些SpringBoot的自动配置的数据源和配置 jpa

3.Springboot报错


APPLICATION FAILED TO START
*
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration$ThymeleafDefaultConfiguration.templateEngine(ThymeleafAutoConfiguration.java:158)
The following method did not exist:
org.thymeleaf.spring5.SpringTemplateEngine.setRenderHiddenMarkersBeforeCheckboxes(Z)V
The method’s class, org.thymeleaf.spring5.SpringTemplateEngine, is available from the following locations:
jar:file:/D:/JavaWeb/SpringbootMengSou/target/demo-0.0.1-SNAPSHOT/WEB-INF/lib/thymeleaf-spring5-3.0.9.RELEASE.jar!/org/thymeleaf/spring5/SpringTemplateEngine.class
It was loaded from the following location:
file:/D:/JavaWeb/SpringbootMengSou/target/demo-0.0.1-SNAPSHOT/WEB-INF/lib/thymeleaf-spring5-3.0.9.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.thymeleaf.spring5.SpringTemplateEngine

报错原因:springboot和thymeleaf版本不兼容

解决方法:将pom.xml中的下面部分换成下面内容主要就是 parent 里面的 version

<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.10.RELEASE</version>
    <relativePath/> <!— lookup parent from repository —>
</parent>
<groupId>SpringbootMengSou</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>SpringbootMengSou</name>
<description>Demo project for Spring Boot</description>

4、Template might not exist or might not be accessible

这是因为controller的方法没有加@ResponseBody