美文网首页
SpringBoot跳坑汇总

SpringBoot跳坑汇总

作者: 帅可儿妞 | 来源:发表于2018-12-25 14:23 被阅读22次

为了后期项目做分布式好拆分,也是为了模块化管理,现在有很多人在创建项目的时候都使用Maven继承的方式搭建项目,然而那里有些坑一不小心就跳进去了,这里把我遇到的一些坑总结一下

  1. 项目install的时候一直找不到依赖项目的类,报错package <依赖项目包> does not exist以及cannot find symbol

    • 在创建SpringBoot项目的时候,SpringBoot默认都会在POM的最后添加一个spring-boot-maven-plugin,这个插件的一个作用就是在install/package等之后生成一个可执行jar,如果我们的项目现在是依赖的方式,而不是分布式部署的话,所有的jar的项目中,不需要这个插件,干掉即可
    • 补充一下,如果依赖项目中spring-boot-maven-plugin的配置中没有找到主类,就会报错找不到主类
  2. 父项目dependencyManagement 标签中管理jar版本,'dependencies.dependency.version' for xxx.yyy:ooo:jar is missing.

    [INFO] Error stacktraces are turned on.
    [INFO] Scanning for projects...
    [ERROR] [ERROR] Some problems were encountered while processing the POMs:
    [ERROR] 'dependencies.dependency.version' for org.mybatis:mybatis:jar is missing. @ line 22, column 21
     @ 
    [ERROR] The build could not read 1 project -> [Help 1]
    org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
    [ERROR] 'dependencies.dependency.version' for org.mybatis:mybatis:jar is missing. @ line 22, column 21
    
    • 没有找到问题在哪,但是我是这么做的:从父pom项目中干掉子模块的引用,单后单独每个进行clean和install,最后成功,可能是缓存问题,但目前还不知道是哪块的缓存。如果你确定自己写的没有问题,或者找不到问题在哪可以这样试试。
    • 需要补充的一点是,继承从父pom继承的项目中type类型是不会继承的
  3. 把项目中的application.properties修改为application.yml之后,项目启动报错,文件汇总是空的,项目却报错,如下:

    2018-12-29 09:16:59.098  INFO 14064 --- [  restartedMain] utoConfigurationReportLoggingInitializer : 
    
    Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
    2018-12-29 09:16:59.106 ERROR 14064 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 
    
    ***************************
    APPLICATION FAILED TO START
    ***************************
    
    Description:
    
    Cannot determine embedded database driver class for database type NONE
    
    Action:
    
    If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
    
    • 打开debug之后,报错信息
    org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
    
    • 然而,数据库连接信息都在依赖项目的application.properties中配置,开始以为是读取不到jar中的配置文件,但是又束手无策,于是项目回滚找问题,发现修改了配置文件的后水名;
    • 于是乎,在最新的代码上修改yml回到properties,启动发现又好了,真的不知道这是什么情况,有大侠知道吗?
  4. SpringBoot中,项目的parent影响当前项目打包的位置

    • 我没看错吧???确实令我挺意外的,我们项目组有一个common项目,之前设置的parent是spring-boot-starter-parent,但是同事下载下来代码去运行死活报错:找不到common.jar
    • 出于好奇,仔细看了install的日志,发现安装到parent所在的目录中了:
      [INFO] Installing D:\XXXxxx\common\target\common-0.0.1.jar to D:\Documents\MVNRepo\org\springframework\boot\common\0.0.1\common-0.0.1.jar
      
    • 最后才知道,项目开始的时候,不需要写groupId,后来parent修改为spring-boot-starter-parent后没有及时添加groupId,没有填写就会使用父项目的groupId,以致于造成的假象:项目的parent影响当前项目打包的位置
  5. SpringBoot项目启动的时候有个警告,如下:

    WARN  org.mybatis.spring.mapper.ClassPathMapperScanner - No MyBatis mapper was found in '[com.zhiyi.ai.health.core.registration, com.zhiyi.ai.health.web]' package. Please check your configuration.
    
    • 为了方便就把之前项目的部分xml配置直接导入到项目中,使用@ImportResource来导入,往上查证后,说是配置文件中多了个MapperScannerConfigurer,于是把这个bean配置删除,但是也不能不写,于是把之前注释掉的@MapperScan重新启用,重新启动正常了
    • 之前在搭项目的时候,用的也是@MapperScan,但是一直不生效,现在还是原样放回去,又是生效的,警告问题也迎刃而解,个人感觉idea有时候的缓存问题挺严重的,报错死活解决不了,吃个饭回来,什么也没动,竟然也成功了;
    • 至于为什么手动配置MapperScannerConfigurer不成功,而注解@MapperScan却可以,这个问题目前还没有得到答案,正在探索中;
  6. APPLICATION FAILED TO START

    • Field helloService in org.shreker.sdz.demo.consumer.controller.HelloController required a bean of type 'org.shreker.sdz.demo.api.service.IHelloService' that could not be found.
      • 情况1:在多模块项目中,并且是模块之间以jar依赖的方式引入的时候,必须在web层的主程序上添加注解:
        @ComponentScan("<base-package>")
      • 情况2:在多模块项目中,并且是模块之间以jar依赖的方式引入的时候,pom中必须引入接口的实现,即provider,可在使用了dubbo或者springcloud之后删除;

相关文章

  • SpringBoot跳坑汇总

    为了后期项目做分布式好拆分,也是为了模块化管理,现在有很多人在创建项目的时候都使用Maven继承的方式搭建项目,然...

  • iOS 13Beta测试问题---持续更新

    汇总下遇到的beta版本的问题吧,先说自己现在遇到的吧,方便大家跳坑。 1,私有KVC [textField se...

  • springboot 踩坑之路(一)

    springboot+spring security 权限验证的坑 关于springboot+spring sec...

  • 关于“跳坑”的

    坑不要跳!有些坑是跳不了的……去找那些我现在“跳不进去”的坑,然后挨个跳一下看看。不跳不知道坑有多大,俗话说机会总...

  • 微服务学习网址

    Spring Boot学习资料汇总: http://www.ityouknow.com/springboot/2...

  • 跳坑

    自己的一生虽然有些波折,总的来说,还是一步一个脚印地走到今天,也认真践行了“天道酬勤”、“一份付出一份收获”,我对...

  • 跳坑

    周一加入新成员

  • 跳坑

    哈哈,这家伙又跳到坑里了,估计惨得很呀!现实生活中,普遍认为,跳坑是祸事,遇见都会避之不及! 其实,任何事...

  • SpringBoot非官方教程 | 终章:文章汇总

    SpringBoot非官方教程 | 终章:文章汇总 springboot非官方教程,可能最接近于官方的一个教程,大...

  • SpringBoot整合Activiti

    SpringBoot整合Activiti SpringBoot 2.x整合Activiti6.0出现各种坑 首先引...

网友评论

      本文标题:SpringBoot跳坑汇总

      本文链接:https://www.haomeiwen.com/subject/ptrflqtx.html