V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
singleion
V2EX  ›  问与答

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

  •  
  •   singleion · 2018-04-23 10:53:31 +08:00 · 2150 次点击
    这是一个创建于 2187 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在学习 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,求解决方案,不胜感激!

    9 条回复    2018-04-26 15:16:45 +08:00
    letitbesqzr
        1
    letitbesqzr  
       2018-04-23 11:24:33 +08:00   ❤️ 3
    这排版,看都不想看。。
    lifespy
        2
    lifespy  
       2018-04-23 11:41:41 +08:00
    这排版,看都不想看。。+1
    blackboom
        3
    blackboom  
       2018-04-23 11:42:03 +08:00
    @letitbesqzr 这个问题难啊!
    night98
        4
    night98  
       2018-04-23 12:01:42 +08:00 via Android
    给堆栈信息和配置信息,你这解释看不明白
    starmoon1994
        5
    starmoon1994  
       2018-04-23 12:55:26 +08:00
    哥们 明显是数据库相关的配置没写正确 和 thymeleaf 没关系
    sqlSessionTemplate 这个类你都没看过么
    alvinbone88
        6
    alvinbone88  
       2018-04-23 13:30:53 +08:00
    这个错误已经很明显了,spring.datasource.url 未指定
    回去好好看看教程,是不是开头配置数据库的部分漏了
    rapperx2
        7
    rapperx2  
       2018-04-23 13:38:58 +08:00
    啊我的眼睛,这一坨是什么啊?
    singleion
        8
    singleion  
    OP
       2018-04-23 14:17:00 +08:00
    问题已解决,谢谢各位!关于排版的问题,第一次用这个,写的时候排版挺好的,已发布就变成一坨了,尴尬,浪费各位视力了,不好意思!
    jack80342
        9
    jack80342  
       2018-04-26 15:16:45 +08:00
    这几天翻译了最新的 Spring boot 官方文档,https://www.gitbook.com/book/jack80342/spring-boot/details
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5615 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 03:11 · PVG 11:11 · LAX 20:11 · JFK 23:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.