springboot 整和 mybitis 与 thymeleaf 时出现的奇葩问题,望各位大神指教!

2018-04-23 10:53:31 +08:00
 singleion

在学习 springboot 框架时遇到这个问题,首先整合了 springboot 与 mybatis,没有用模板框架,controller 直接返回数据,运行之后服务启动正常,浏览器访问正常,数据显示正常! 然后开始整合模板 thymeleaf 时出现问题了,我先是配置 application.yml 中的 thymeleaf 的相关配置,和 thymeleaf 的 pom 文件依赖,配置信息和依赖如下: #模板类配置 spring: freemarker: cache: false prefix: classpath:/templates/ suffix: .html encoding: UTF-8 content-type: text/html mode: HTML5 <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-thymeleaf</artifactid> </dependency> 然后写好 controller 和模板类,开始运行项目,出现各种异常,详情如下: Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-configured.报出这个异常后,我在启动类注解上加上这个:@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})然后再重新启动,上面这个问题不报了,出现了个新的问题,详情如下:java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required,求解决方案,不胜感激!

2162 次点击
所在节点    问与答
9 条回复
letitbesqzr
2018-04-23 11:24:33 +08:00
这排版,看都不想看。。
lifespy
2018-04-23 11:41:41 +08:00
这排版,看都不想看。。+1
blackboom
2018-04-23 11:42:03 +08:00
@letitbesqzr 这个问题难啊!
night98
2018-04-23 12:01:42 +08:00
给堆栈信息和配置信息,你这解释看不明白
starmoon1994
2018-04-23 12:55:26 +08:00
哥们 明显是数据库相关的配置没写正确 和 thymeleaf 没关系
sqlSessionTemplate 这个类你都没看过么
alvinbone88
2018-04-23 13:30:53 +08:00
这个错误已经很明显了,spring.datasource.url 未指定
回去好好看看教程,是不是开头配置数据库的部分漏了
rapperx2
2018-04-23 13:38:58 +08:00
啊我的眼睛,这一坨是什么啊?
singleion
2018-04-23 14:17:00 +08:00
问题已解决,谢谢各位!关于排版的问题,第一次用这个,写的时候排版挺好的,已发布就变成一坨了,尴尬,浪费各位视力了,不好意思!
jack80342
2018-04-26 15:16:45 +08:00
这几天翻译了最新的 Spring boot 官方文档,https://www.gitbook.com/book/jack80342/spring-boot/details

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/449045

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX